Creating a featured articles section from a particular category
May 26, 2008 · Print This Article
Creating a Featured Articles section for your WordPress blog involves 3 basic steps:
- Create a new category called Featured.
- Place the code (provided below) into sidebar.php.
- Style the Featured section to match the rest of your sidebar.
Featured Articles code
Place the following code in the preferred location of your sidebar—or anywhere else you may want to display your Featured Articles:
<ul>
<?php query_posts('category_name=Featured&showposts=5'); while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
The query_posts function queries the database for all posts in the Featured category and selects the 5 latest posts. Change the 5 to whatever number you want. Then displays the 5 selected posts, in list format, via Post Title.
Styling your Featured Articles section
Enclose your Featured Articles section in a div <div id=”featured”></div> and define it in your style sheet.
#featured ul li a, #featured ul li a:visited {
/* preferred styling here */
}
#featured ul li a:hover {
/* preferred styling here */
}
Now, posts in the Featured category will be displayed in the Featured section.
This process can be applied to any section you may wish to create, anywhere on your blog. If you don’t have a Featured Articles/Posts section yet, give it a try.






















Comments
Got something to say?
You must be logged in to post a comment.