Themes / Design

Plugins / Hacks

Security

SEO

Tutorials

Home » Plugins / Hacks

Display selected posts on the homepage without featured category

Submitted on June 10, 2009 – 13:53hr577 views | No Comments Yet...
Display selected posts on the homepage without featured category

From Alex Denning over at Nometech comes a great hack for magazine style themes with his post "10 Ways to Get That Elusive ‘Magazine’ Look in WordPress".

We are highlighting one hack on that great list, number 7: Display selected posts on the homepage without an extra category.

Most magazine style themes have a featured content part, actually also this theme which was featured before, and these themes want you to create a special category "featured". Then by adding posts to that category visitors will see different posts in the featured content part of the site.

Alex explains that for example when switching themes it is not very useful to have this category "featured" hanging around and therefore the following hack is a great solution in avoiding exactly that.

The trick is to create a custom field called "featured". Then for Posts that you would like to be included in the featured content, you give this custom field a value of 1 (for TRUE).

<?php if (have_posts()) :
while (have_posts()) : the_post();
$customField = get_post_custom_values("img");
if ( (isset($customField[0])) && ($customField[0] == "featured") ) {
//Custom field have featured as a value, display info
the_title();
the_excerpt();
}
endwhile;
endif;
?>

PS Alex got the original idea from Jean over at WPRecipes

Popularity: 57% [?]

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.