Make text bigger  Make text smaller  Toggle background color  Bookmark/Share


OOPOST TYPES: METHODS PART 2 – OBJECT ORIENTED WORDPRESS 3.0 APP

This is a second partial of office building a WordPress 3.0 law post sort class. In this educational we’ll set up a methods which a category can use, as well as finish a category which was proposed being combined in a initial partial of a educational series.

www.FeedBurner.com) OOPost Types: Methods Part 2 – Object Oriented WordPress 3.0 App

The rest is here:
OOPost Types: Methods Part 2 – Object Oriented WordPress 3.0 App


Get Auto Caffeinated Content for Your WordPress Blog



INDIVIDUAL DESIGN FOR ANY PAGE

The blog has a Theme as good as for any page an additional character sheet. This stream direction of individuality for any calm is really usual today. Even with WordPress, we can do so; there have been multiform possibilities. One probability is to create, formed on a title, a particular stylesheet.
By default, a category choice of duty body_class() has already a lot of possibilities. More individuality can be reached with a pretension or ID.
It is positively not value for a normal blog sourroundings though for a site with small calm it functions flattering well. As we have implemented in this case.

If a page is loaded, afterwards we can pass a title. If we make use of this a single in a physique tab as ID or category as good as afterwards emanate for any ID or class a style, a right pattern will be loaded.

Alternatively, we can work with a ID of a page or article, duty the_ID() passes it. Please note, IDs as good as classes might not begin with a series as good as thus we contingency supplement a fibre before, for example:

<div id="page-<?php the_ID(); ?>">

As a last alternative, we would similar to to discuss which we can enhance a duty body_class() around Hook with own classes. So we can have a pretension of a page/post around offshoot in this function.

function fb_title_body_class($classes) {
	global $post;
 
	$classes[] = sanitize_title_with_dashes( get_the_title( $post->ID ) );
 
	return $classes;
}
add_filter( 'body_class', 'fb_title_body_class' );

In a following I’m display we a simplest box around title, so which we outlay usually this category as good as as well as body_class() is not used.

With a assistance of a Title

Put a stylesheet in a header of your Theme:

<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/custom.css" type="text/css" media="screen" />

Alternatively, this is integrated around Hook wp_head if a specific page is loaded, so we bucket a pithy character piece usually if it is needed. Everything happens in a functions.php of your Theme.

in your physique tab of page.php is a pretension of a page:

<body class="<?php echo sanitize_title_with_dashes( get_the_title() ); ?>">

Therefore a page “My Home” has a physique tag:

<body class="my-home">
and so on...

in your custom.css we conclude all character for category home: for example

.my-home a { color: #090; text-decoration: none; }
.my-home a:visited { color: #999; text-decoration: none; }
.my-home a:hover { color: #f60; text-decoration: none; }

in a strange Theme it looks similar to this:

a { color: #009; text-decoration: underline; }
a:visited { color: #999; text-decoration: underline; }
a:hover { color: #c00; text-decoration: underline; }

I consider it’s an proceed with a lot intensity as good as so we leave it to your creativity. So if we would similar to to have for any page a opposite character sheet, this is an easy solution.


Related posts:


WP Engineer Favicon Thanks for subscribing a feed! Sponsor a WP Engineer Blog as good as get your code in front of multiform hundred users per day!
© WP Engineer Team, All rights indifferent (Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)

View post:
Individual Design for any Page


Get Auto Caffeinated Content for Your WordPress Blog



PREVENT SQL INJECTION ATTACKS IN WORDPRESS

SQL injection is a really renouned technique to penetrate in to database of a website by regulating improper user submit with unescaped characters. It occurs when developer designs a bad database covering for an application. In WordPress, a database covering is $wpdb class, that is well-designed for this purpose. This category as well as WordPress itself have a little built-in functions to assistance developers get absolved of any SQL injection attack.

www.FeedBurner.com) Prevent SQL Injection Attacks In WordPress Prevent SQL Injection Attacks In WordPress

The rest is here: 
Prevent SQL Injection Attacks In WordPress


Get Auto Caffeinated Content for Your WordPress Blog



WORDPRESS FILTER EXAMPLES – CHANGING ATTRIBUTES WHEN ADDING IMAGES TO POSTS

Typically, when we supplement an picture to your posts, WordPress assigns sure attributes to a img tag, depending on what we chose in a picture upload editor

www.FeedBurner.com) WordPress Filter Examples – Changing Attributes When Adding Images to Posts WordPress Filter Examples – Changing Attributes When Adding Images to Posts

Read a strange post:
WordPress Filter Examples – Changing Attributes When Adding Images to Posts


Get Auto Caffeinated Content for Your WordPress Blog



FEED CACHE IN WORDPRESS

WordPress already offers a probability of own functions to review feeds as well as have make make make use of of of of it in your blog. Since chronicle 2.8 of WordPress, a code new underline is in have make make make use of of of of for that. So there have been dual ways to work with feeds in WordPress, as well as in both functions, a interpretation is cached. But this is not regularly wanted, so we uncover how to take change on caching of a dual functions.

fetch_feed() Since WordPress 2.8

With chronicle 2.8 of WordPress, they supplement a category SimplePie in to a core. SimplePie has regularly renowned by a really fast growth as well as a fast user-friendly class. Before MagpieRSS has been used, that in most cases was not accessible as well as a growth is rsther than slow. For a tiny time SimplePie is no longer be confirmed by a developer, that disturbed a developer community. But developers from a WordPress group took caring of it as well as keep a category alive. More report can be find on a blog WP Dev Updates

Now a category is in a core of WordPress as well as is able of generating RSS as well as ATOM feeds. It uses a cache of WordPress as well as can be tranquil around a hook.

But initial a tiny representation to review a feed with a category in WordPress.

<?php
include_once(ABSPATH . WPINC . '/feed.php');
$rss = fetch_feed('http://bueltge.de/feed/');
$rss_items = $rss->get_items( 0, $rss->get_item_quantity(5) );
if ( !$rss_items ) {
    echo 'no items';
} else {
    foreach ( $rss_items as $item ) {
        echo '<p><a href="' . $item->get_permalink() . '">' . $item->get_title() . '</a></p>';
    }
}
?>

The tiny representation reads my feed as well as earnings a final 5 entries.

Essential is a duty fetch_feed(). This duty has a offshoot that can have change on caching – wp_feed_cache_transient_lifetime.
The customary of a cache is set to twelve hours ( 43,200 ), that is not regularly a a one preferred sourroundings for users. The worth is operated on a process WP_Feed_Cache_Transient(), parameter $lifetime. Therefore, it is receptive to advice to have make make make use of of of of a following tiny query, be it in a Plugin or in a functions.php of a theme.

add_filter( 'wp_feed_cache_transient_lifetime', create_function( '$a', 'return 1800;' ) );

In this example, we set a cache to thirty minutes. With a assistance of Conditional Tags we can carry out a total of it so that a cache-hook is customarily activated when we click on a page (is_page()) or for e.g. we have been in a front finish (!is_admin()) of a blog. Here we contingency simply have make make make use of of of of a opportunities as well as conform to your own needs.

A tiny probability we would similar to to indicate out more, available as of WordPress 2.9 (ticket 11117), to facilitate debugging for developers. Thus, a cache is infirm in a environment, if a consistent WP_DEBUG is set, that can be critical right away as well as then. Setting a consistent is customarily finished in a wp-config.php of a installation, or as pick in a Plugin.

function do_not_cache_feeds(&$feed) {
	$feed->enable_cache(false);
}
 
if ( defined('WP_DEBUG') && WP_DEBUG )
	add_action( 'wp_feed_options', 'do_not_cache_feeds' );

fetch_rss()

Another duty is fetch_rss(), that was set with WordPress 2.8 on a torment list. As an alternative, a on top of duty is active. Current is fetch_rss() still accessible as well as is additionally supported. Therefore, for completeness, additionally a probability to change a cache.

Here an e.g. to review feed as well as outlay a final 5 entries of a feed

<?php
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss('http://bueltge.de/feed/');
$rss_items = array_slice($rss->items, 0, 5);
if ( empty($rss_items) ) {
    echo 'no items';
} else {
    foreach ( $rss_items as $item ) {
        echo '<p><a href="' . $item['link'] . '">' . $item['title'] . '</a></p>';
    }
}
?>

Here, a duty fetch_rss() is used for celebration of a mass as well as a cache can be altered around a constants. This contingency tangible possibly without delay in wp-config.php where they will request globally to all applications, or we need to confederate them in to a own functions.

define('MAGPIE_CACHE_ON', 0); // deactivate cache
define('MAGPIE_CACHE_AGE', 60*60) // Cache 1 hour in seconds

Conclusion

Since WordPress motionless not to await MagpieRSS any longer in a future, we should customarily understanding with SimplePie as well as not with a second possibility.


Related posts:


WP Engineer Favicon Thanks for subscribing a feed! Sponsor a WP Engineer Blog as well as get your code in front of multiform hundred users per day!
© WP Engineer Team, All rights indifferent (Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)

Read more:
Feed Cache in WordPress


Get Auto Caffeinated Content for Your WordPress Blog



STYLING DIFFERENT POSTS IN DIFFERENT WAYS WITH POST_CLASS

Leader Post Class

With WordPress 2.7 came a post_class function. This gives a set of CSS classes to a post, depending on what’s in a post (e.g. formed on what difficulty it is in).

The formula which we make make make make make make make use of of of of of of of in your template to make make make make make make make use of of of of of of of this is simply similar to this:

1
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

While this is a illusory duty for becoming opposite a post’s display, a classes which it outputs have been essentially utterly limited. Luckily, we can supplement a own, as well as we can additionally supplement a own energetic classes.

Basically what we meant by this is which by regulating a small additional lines of PHP, we can supplement a own classes in to a post_class duty depending on a small alternative post information.

The default classes which have been outlay are:

  • post-id, where id is a post’s id
  • post type, which by default have been post, page as well as attachment
  • sticky, for posts noted as gummy on a post write panel
  • hentry, for hAtom compliance
  • category-category-name, so if your difficulty was wordpress, it would be category-wordpress
  • tag-tag-name, so if your tab was php, it would be tag-php

NB. This post uses a small functions usually introduced in WordPress 2.8.

Author Styling

A lot of blogs character their authors’ comments otherwise to visitors’ comments, so because not character a single author’s posts otherwise to another’s?

First of all, to get a writer of a post, supplement this line prior to a begin of your loop.

1
<?php $author = get_the_author_meta('display_name'); ?>
  1. This creates a brand new non-static called $author…
  2. And assigns a worth of get_the_author_meta to it, privately a author’s arrangement name.

If we instruct to make make make make make make make use of of of of of of of alternative aspects of a author’s meta, take a demeanour at a get_the_author_meta entrance in a codex.

And afterwards to supplement which as a category to post_class, supplement this line:

1
<?php post_class('box ' . $author); ?>
  1. As an e.g. of a immobile category in as well as with this energetic class, I’ve combined a capricious ‘box’ class.
  2. Note a space prior to a shutting apostrophe; this ensures which there is a space in between it as well as a energetic class.
  3. We concatenate a writer non-static to outlay a name of a writer as a class.

We can right away character any post depending on a author. Just as an example, we’ll shift a limit colour.

1
2
3
4
5
6
.Alex {
border: 1px solid #0066CC;
}
.Martin {
border: 1px dashed #CC0000;
}

Author Post Class

Show Post Popularity with CSS

This is a small some-more complicated, though ultimately, we’re starting to make make make make make make make use of of of of of of of a volume of comments on a post to furnish a opposite category accordingly.

You might instruct to shift these numbers to fit a normal series of comments we get on a post to establish what is some-more popular, though a judgment stays a same.

To get a volume of comments we need to supplement a following code, this time inside a loop.

1
2
3
4
5
6
7
8
9
10
11
12
<?php
	$postid = get_the_ID();
	$total_comment_count = wp_count_comments($postid);
		$my_comment_count = $total_comment_count->approved;
	if ($my_comment_count <10) {
		$my_comment_count = 'new';
	} elseif ($my_comment_count >= 10 && $my_comment_count <20) {
		$my_comment_count = 'ermerging';
	} elseif ($my_comment_count >= 20) {
		$my_comment_count = 'popular';
	}
?>
  1. We emanate a initial non-static as well as set a post’s ID as a value.
  2. Using which non-static we can entrance a criticism equate for which post regulating wp_count_comments, assigning which to an additional variable.
  3. That duty gets all comments, either spam, available mediation or approved, though luckily we can contend to usually get a authorized equate regulating ->approved.
  4. Now we can exam a worth of a $my_comment_count non-static regulating php operators.

Now for any category we have created, we supplement a CSS rule. Because a indicate of this is to uncover an article’s recognition visually, it creates clarity to make make make make make make make use of of of of of of of a small kind of spectrum, I’m regulating yellow to red.

1
2
3
4
5
6
7
8
9
.new {
border: 1px solid #FFFF00;
}
.emerging {
border: 1px dashed #FF9933;
}
.popular {
border: 1px dashed #CC0000;
}

Popularity Post Class

Custom Fields

To get a idealisation carry out over a post’s arrangement we can spin to custom fields.

First of all we supplement a law margin worth as well as pass span to a post:

Custom Field Post Class

So in this case, we supplement dual classes, arrangement my mood when we wrote a post, as well as what a continue was doing. Just to uncover how which can be used, we can supplement a small CSS to uncover a credentials for a weather.

1
2
3
.raining {
background: transparent url('images/raining.jpg') no-repeat right bottom;
}

We can make make make make make make make use of of of of of of of a following formula to get a law field:

1
<?php $custom_values = get_post_meta($post->ID, 'post-class'); ?>

Remembering to supplement a $custom_values non-static to a post_class function.

Custom Field Output Post Class

Taking a thought further

Some alternative ways we can make make make make make make make use of of of of of of of post_class boldly have been with the_time, checking for differences in the_time as well as the_modified_time or even with word count. See what engaging ways we can come up with to shift a post’s arrangement depending on a small of a energetic aspects.

 Styling Different Posts in Different Ways With Post_Class

b9375f06f1leader-post-class-150x38 Styling Different Posts in Different Ways With Post_Class

See a strange post: 
Styling Different Posts in Different Ways With Post_Class


Get Auto Caffeinated Content for Your WordPress Blog



IDENTIFY AUTHORS WITH GRAVATARS

Since WordPress chronicle 2.5, it is simpler to embody a Gravatar of a criticism writer in a comments. WordPress offers a underline which is easy to make make use of of as well as it brings a little parameters with. In sequence to make make use of of as well as how to embody a Gravatar, we would impute to a essay „ Gravatar Use Easy “.

 Identify Authors With Gravatars

More here: 
Identify Authors With Gravatars


Get Auto Caffeinated Content for Your WordPress Blog

Pages