Featured Post Sidebar Widget In WordPress

Posted by


Many of the wordpress users requires to display featured post in the sidebar using sidebar widget. For that here is the solution:

1. Download and install the PHP Code Widget. This will allow to use PHP code in a custom text widget.


2. Add this code in body of the text widget:

$featuredPost = new WP_Query();
while ($featuredPost->have_posts()) : $featuredPost->the_post();
<h2>Featured Post</h2>
<p id=”featured”><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a> </p>
<?php endwhile; ?>

It will creates a secondary WP Loop using the WP_Query function. “tag=featured” will only show posts with a tag of “feature,” “showposts=1” will only show 1 post, and “orderby=date” will only show the most recent post. So we’re saying “Show the most recent single post with a ‘featured’ tag”.

3. Create the link to display the post title like excerpt or any other data associated with the post using template tags.


4. Then tag whatever post you want to be featured with a “featured” tag and it will show up in the sidebar.

5. When you want to change the featured post just move the tag to the new post.  Please remember that if you have two or more featured posts with the featured tag, it will default to showing the most recent.


Shane G.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.