The Nice Way To Mention Your Recent Articles in WordPress SideBar

written by aext on December 27, 2009 in WordPress with 34 comments

People asked me how I mention my recent articles in WordPress sidebar by display post thumbnails and titles with a well-styled. Today, I would like to response their request. This way is being used in some blogs. I’m not sure if they are using the same method as mine, but at least we will get the same result.

When design blog theme in WordPress, I always look for non-using plugins solution. People asked me which plugin I’m using for this sidebar. No, the answer is NO.

There are a lot of WordPress plugins to display your recent articles, popular articles to mention your posts in the sidebar widget. However, you forgot that you can do the same with a simple posts query using WP_Query(); function.

To begin, create new posts object that you will call by will have_posts() and display your posts within the loop



This function is called to see if there are any posts to show. Using the while loop, and we can use have_post() as the condition. This will iterate around as long as there are posts to show.

In my case, I’m using iterations, the_post(), within the while loop to iterate around as long as there are posts to show.


  <?php $recent = new WP_Query("showposts=35"); while($recent->have_posts()) : $recent->the_post();?>

      <a title="Permanent Link to <?php the_title(); ?>"rel="nofollow"href="<?php the_permalink() ?>">

        <?php if(get_post_meta($post->ID, "image", true)): ?>
            <img src="<?php bloginfo('template_url'); ?>/scripts/thumb.php?src=<?php echo get_post_meta($post->ID, "image", true); ?>&w=25&h=25&zc=1"alt="<?php the_title(); ?>" />
        <?php else: ?>
            <img src="<?php bloginfo('template_url'); ?>/images/thumbnail.png"width="25"height="25"alt="<?php the_title(); ?>" />    
        <?php endif; ?>

      <span><?php the_title(); ?></span></a>

  <?php endwhile; ?>


This code above will check if you have post meta name is image, it will display the thumbnail using timthumb script. Timthumb is a small php script for cropping, zooming and resizing web images (jpg, png, gif). Perfect for use on blogs and other applications.


You can change the number of post will be displayed and set the condition to display number of posts in single page larger than other page because the post page is always longer than others, right?

CSS Bonus:

.widget ul {
    margin:5px auto 8px;
    padding:0 0 2px;

.widget ul li {
    padding:5px 0 0;

.widget ul li a {
    border-bottom:0 dotted #DDDDDD;
    font-family:Georgia,"Nimbus Roman No9 L",serif;

.widget ul li img {
    border:3px solid #DFDFDF;

.widget ul li span {


We don’t need to use any plugin for display not only such a simple list of post like that but also other simple things in WordPress. WordPress provide us WordPress Codexwhich contains a thousand of Function References. If you want to build your own WordPress theme with unique style, the first thing you need is check out how WordPress function works. Good luck, hope see more beautiful WordPress themes from the web community.