Title: WordPress php code for recent posts?
Last modified: August 19, 2016

---

# WordPress php code for recent posts?

 *  [derren-b](https://wordpress.org/support/users/derren-b/)
 * (@derren-b)
 * [17 years, 3 months ago](https://wordpress.org/support/topic/wordpress-php-code-for-recent-posts/)
 * I have a div, in which i was to show titles of recent posts, any idea of what
   the code will be like? prob show latest 5 posts if that helps? Cheers.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 3 months ago](https://wordpress.org/support/topic/wordpress-php-code-for-recent-posts/#post-1015050)
 * Use a plugin: [http://wordpress.org/extend/plugins/search.php?q=recent+posts](http://wordpress.org/extend/plugins/search.php?q=recent+posts)
 *  [fas.khan](https://wordpress.org/support/users/faskhan/)
 * (@faskhan)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/wordpress-php-code-for-recent-posts/#post-1015298)
 * Or use this code:-
 *     ```
       // GET POSTS
       		$r = new WP_Query(array('showposts' => $show, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
       		if ($r->have_posts()) :
       ?>
       		<?php echo $before_widget; ?>
       			<?php echo $before_title . $title . $after_title; ?>
       			<ul>
       			<?php  while ($r->have_posts()) : $r->the_post(); ?>
       			<li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
       			<?php endwhile; ?>
       			</ul>	
   
       <?php
       		// echo widget closing tag
       		echo $after_widget;
   
       		wp_reset_query();  // Restore global post data stomped by the_post().
       		endif;
       ```
   
 *  [fas.khan](https://wordpress.org/support/users/faskhan/)
 * (@faskhan)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/wordpress-php-code-for-recent-posts/#post-1015299)
 * oh, and $show is the number of posts to be showed.
 * Do $show = 5, and it will show 5 most recent posts.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘WordPress php code for recent posts?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [fas.khan](https://wordpress.org/support/users/faskhan/)
 * Last activity: [17 years, 2 months ago](https://wordpress.org/support/topic/wordpress-php-code-for-recent-posts/#post-1015299)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
