WordPress: Show latest posts in the sidebar

WP: Show latest posts in the sidebar

Here is simple but useful WordPress code to show latest posts on your sidebar. Code written by catswhocode.com. How to use this code? Just open up the sidebar.php file and insert the following code to display the four latest posts in an unordered list:

<?php query_posts(‘showposts=4’); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li>
<?php endwhile; ?>

How to show more or less latest posts in sidebar?
<?php query_posts(‘showposts=4‘); ?> where is 4 insert how much posts you want to see in your sidebar.

Source: CatsWhoCode

2 thoughts on “WordPress: Show latest posts in the sidebar

Leave a Reply

Your email address will not be published. Required fields are marked *