SMOR.tv  > Tutorials  > WordPress Tutorials  > WordPress Featured Post Tutorial (Using Custom Fields)

WordPress Featured Post Tutorial (Using Custom Fields)

08.02.2009 Bookmark and Share

This tutorial will show you how to modify your WordPress loop to only display posts that are marked as featured. We will be using a custom field to set posts as featured and in turn, featured posts are not limited to one category. Also, because we’re going to be using custom fields it’s transparent to the visitors unlike tags or categories which are visible. Alternatively, you could use a “Featured” category and loop through that specific category.

  1. Find index.php in your template directory, which can be found at: /wp-content/themes/yourthemename/index.php.
  2. Make a copy of the index.php and call it featured.php.
  3. Open up featured.php and add the following code at the very top of the document. This is the code for creating a Custom WordPress Template.
    <?php
    /*
    Template Name: Featured Posts
    */
    ?>
  4. Towards the top of the document you should see where the loop is starting, lines 2 and 3 should already be in your document. Copy line 1 and insert it before before the other 2 lines so it looks like the following:
    <?php query_posts('meta_key=is_featured&meta_value=yes');  ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?> 
  5. What this is doing is telling WordPress to loop through posts that have a custom field of “is_featured” set to “yes”. Save / Upload featured.php to your template directory and create a new page using the newly created Featured Posts template. If you want this to be your homepage, then go to Settings > Reading, and set your new page as your front page.
  6. Now to add a featured post add a new post (or edit an existing one), and under the editor add a new custom field for “is_featured”. Then give it a value of “yes”. Update the post, then go back to your Featured Posts page and you should see the featured post.
  7. As I mentioned from the start, there’s many ways of creating featured posts such as categories, tags, etc. Personally I find this method to be best for a few reason…
    • Using categories means featured posts will probably need 2 categories, one for the real category, and the other just setting it as featured.
    • The category method can influence your permalinks, which may make them less descriptive.
    • Another method is tag based, but many SEO plugins automatically generated keywords from tags. Having “featured” as a keyword on many pages isn’t going to help with Search Engine Optimization.
    • Plug-ins are a good option, but in my opinion somewhat unnecessary for such a simple task.
    • The main disadvantage of not using tags or a featured category is users can’t easily view an archive page with all your featured posts.

Sam Morris WordPress Tutorials

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

  1. kris
    August 31st, 2009 at 08:38 | #1

    What a beautiful website you have! This will be my inspiration for using javascript for design.

  2. Francis
    October 4th, 2009 at 03:04 | #2

    Thanks a lot for this.. exactly what I googled for :)

  3. December 24th, 2009 at 07:33 | #3

    Thanks! That was exactly what I needed.

  1. August 2nd, 2009 at 18:47 | #1
  2. November 16th, 2009 at 15:39 | #2