Jul
31

Hi,

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.

http://wordpress.org/extend/plugins/php-code-widget/

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

<?php
$featuredPost = new WP_Query();
$featuredPost->query(‘tag=featured&showposts=1&orderby=date’);
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.

http://codex.wordpress.org/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.

Thanks,

Shane G.

Popularity: 1%

Related posts:
  1. Featured Tag Widget WordPress Plugin Hi, This plugin is added in sidebar which shows a...
  2. Highlight Post Widget Plugin For WordPress Hi, This plugin is used to display Recent Posts sorted...
  3. How To Display Single Post Contents In Sidebar Of WordPress Blog? Hello All, In order to display single post in wordpress...
  4. How To Display Sidebar At Index Page For Single Post? Hello All, In order to display sidebar at index page...
  5. How To Get WordPress Post ID outside the Loop as PHP variable Hi, In the wordpress loop section, each posts displayed on...

Leave a Reply

You must be logged in to post a comment.