Title: Display 5 recent posts in single.php?
Last modified: August 31, 2016

---

# Display 5 recent posts in single.php?

 *  [makta112](https://wordpress.org/support/users/makta112/)
 * (@makta112)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/display-5-recent-posts-in-singlephp/)
 * Hi,
 * I’m trying to display the 5 most recent posts in single.php using this:
 *     ```
       <ul>
       <?php
       $latest = get_posts('numberposts=5');
       foreach( $latest as $post ):
       ?>
       <li><?php the_time(get_option('date_format')); ?> | <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
       <?php endforeach ?>
       </ul>
       ```
   
 * Is it ok to use this code in single.php to display multiple posts?
 * Also, if it’s ok, is it possible to hide the current post from showing up in 
   the list over the most recent posts??
 * Thanks.

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/display-5-recent-posts-in-singlephp/#post-7066617)
 * for details, review:
    [https://codex.wordpress.org/Template_Tags/get_posts#Examples](https://codex.wordpress.org/Template_Tags/get_posts#Examples)
 * modified code (untested):
 *     ```
       <ul>
       <?php
       $this_post = $post->ID;
       $latest = get_posts( array( 'posts_per_page' => 5, 'post__not_in' => array( $this_post ) ) );
       foreach( $latest as $post ): setup_postdata( $post );
       ?>
       <li><?php the_time(get_option('date_format')); ?> | <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
       <?php endforeach;
       wp_reset_postdata(); ?>
       </ul>
       ```
   
 * `get_posts()` [https://codex.wordpress.org/Template_Tags/get_posts](https://codex.wordpress.org/Template_Tags/get_posts)
   uses the same parameters as `WP_Query()` [https://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters](https://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters)
 *  Thread Starter [makta112](https://wordpress.org/support/users/makta112/)
 * (@makta112)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/display-5-recent-posts-in-singlephp/#post-7066627)
 * Thanks! That works 🙂
    I want the content of each post to show up below the title.
   How would I do that? I tried using
 * > <?php the_content(); ?>
 * But it only shows an excerpt. I want for the FULL post to appear. Help please…
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/display-5-recent-posts-in-singlephp/#post-7066633)
 * >  the content of each post to show up below the title.
 * the ‘below’ might need some CSS and possibly some html tags with CSS classes.
 * >  I want for the FULL post to appear.
 * are you using the ‘more tag’ in your posts?
 * this might apply to your case
    [https://codex.wordpress.org/Customizing_the_Read_More#How_to_use_Read_More_in_Pages](https://codex.wordpress.org/Customizing_the_Read_More#How_to_use_Read_More_in_Pages)
 *  Thread Starter [makta112](https://wordpress.org/support/users/makta112/)
 * (@makta112)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/display-5-recent-posts-in-singlephp/#post-7066651)
 * Yes I am.
    Please take a look at the bottom of [this page](http://luxplaster.dk/?p=19980).
   As you can see the posts display a more link instead of the post in full.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/display-5-recent-posts-in-singlephp/#post-7066652)
 * I posted the wrong link, should be
    [https://codex.wordpress.org/Customizing_the_Read_More#More_about_.24moreinstead](https://codex.wordpress.org/Customizing_the_Read_More#More_about_.24moreinstead)
   of just:
 *     ```
       <?php the_content(); ?>
       ```
   
 * have you tried this:
 *     ```
       <?php
       global $more;
       $more = -1;
       the_content(); ?>
       ```
   
 *  Thread Starter [makta112](https://wordpress.org/support/users/makta112/)
 * (@makta112)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/display-5-recent-posts-in-singlephp/#post-7066697)
 * Michael
 * Thanks! That worked.
 * But is it ok to display multiple posts in the single.php? Do you think it will
   mess up something else?
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/display-5-recent-posts-in-singlephp/#post-7066723)
 * > But is it ok to display multiple posts in the single.php? Do you think it will
   > mess up something else?
 * any mess is unlikely, when you are using `wp_reset_postdata()` in the code.

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

The topic ‘Display 5 recent posts in single.php?’ is closed to new replies.

## Tags

 * [single.php](https://wordpress.org/support/topic-tag/single-php/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 7 replies
 * 2 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/display-5-recent-posts-in-singlephp/#post-7066723)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
