WordPress Thumb

Display Recent Post Titles Using wp_query

Today, I’d just like to share with everyone this neat WordPress trick by Libby Fisher from Icode4you.net. It’s a short code that will not only let you display the most recent post titles from a certain category but also let you specify how many titles you want displayed.

Below is the code:

<ul>
<?php
global $cat;
$recentPosts = new   WP_Query();
$recentPosts->query('showposts=5&cat=389');
?>
<?php while ($recentPosts->have_posts()) :   $recentPosts->the_post(); ?>
<li><a   href="<?php the_permalink() ?>"   rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?></ul>

You can increase or decrease the number of posts to be displayed as you like, and don’t forget to change the category id accordingly (both highlighted in red).

Incoming search terms for the article:

Related Posts

Correctly Embed Watermarks In Portrait And Landscape Photos Using Conditional Actions In Photoshop CS6.1

Oregon-Inspired Photoshop Tutorial

Create Google Play’s Tab Navigation Using jQuery And CSS

PS Advanced Compositioning