Title: How to Only Show 3 Posts (PHP Coding)
Last modified: August 22, 2016

---

# How to Only Show 3 Posts (PHP Coding)

 *  [peterruchti](https://wordpress.org/support/users/peterruchti-1/)
 * (@peterruchti-1)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/how-to-only-show-3-posts-php-coding/)
 * Hello – I am using the code below. How do I modify it so that it only displays
   the latest three posts? Thanks for your help!!
 *     ```
       <?php query_posts('category_name='.get_the_title()); ?>
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       	<div>
       	<h3><?php the_title(); ?></h3>
       	<p><?php the_content(); ?></p>
       	</div>
       <?php endwhile; else: ?>no match<?php endif; ?>
       ```
   

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

 *  [shadez](https://wordpress.org/support/users/shadez/)
 * (@shadez)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/how-to-only-show-3-posts-php-coding/#post-5249099)
 * why not use get_posts instead..
 *     ```
       <?php
       $args = array( 'numberposts' => 3, 'category' => 1 ); /* change category id */
       $postslist = get_posts( $args );
       foreach ($postslist as $post) :  setup_postdata($post); ?>
       <div>
       <h3><?php the_title(); ?></h3>
       <p><?php the_content(); ?></p>
       </div>
       <?php endforeach; ?>
       ```
   
 * if using query_posts then set param `'posts_per_page=3'`..
    but ensure you reset
   main loop by calling `wp_reset_query()` afterwards.
 *  [sffandom](https://wordpress.org/support/users/sffandom/)
 * (@sffandom)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/how-to-only-show-3-posts-php-coding/#post-5249104)
 * If you only want to show three posts per page then go into SETTINGS >> READING
   and change “Blog pages show at most” to 3.

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

The topic ‘How to Only Show 3 Posts (PHP Coding)’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [sffandom](https://wordpress.org/support/users/sffandom/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/how-to-only-show-3-posts-php-coding/#post-5249104)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
