Title: Really basic &quot;loop&quot; PHP question&#8230;
Last modified: August 20, 2016

---

# Really basic "loop" PHP question…

 *  [nickaster](https://wordpress.org/support/users/nickaster/)
 * (@nickaster)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/really-basic-loop-php-question/)
 * Hi there.. I’m just starting to learn the php that runs wordpress and have a 
   very basic php question.
 * Say I have a typical front page. But I want the first 5 posts to show *only* 
   headlines. Then the rest of the posts show normally (headline+post+etc…)
 * I can make a standard loop with this code:
 *     ```
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
       <?php endwhile; else: ?>
       <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
       <?php endif; ?>
       ```
   
 * 1) Where in that code can I specify how many posts to choose?
    2) Where in the
   second code would I say… show posts not including the first 5? 3) What would 
   I do about pagination? ie – I only want those 5 headlines to be on page one?
 * THANKS!

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

 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [14 years, 3 months ago](https://wordpress.org/support/topic/really-basic-loop-php-question/#post-2527477)
 * I haven’t goofed around with it in a while but I’m pretty sure it’s all in the
   query string.
 * 1. Before your loop, try adding `query_posts( 'posts_per_page=5' );` above it.
 * 2. and 3. See `http://codex.wordpress.org/Function_Reference/query_posts` and
   this too `http://codex.wordpress.org/Class_Reference/WP_Query`
 * Play around with that, you’ll have lots of fun. 🙂
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/really-basic-loop-php-question/#post-2527582)
 * possibly use a conditional statement, checking the value of `$wp_query->current_post`;
 * example:
 *     ```
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <?php if( $wp_query->current_post < 5 ) {
       //output only headlines
       } else {
       //output normal
       } ?>
       <?php endwhile; else: ?>
       ```
   
 *  Thread Starter [nickaster](https://wordpress.org/support/users/nickaster/)
 * (@nickaster)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/really-basic-loop-php-question/#post-2527708)
 * [@alchymyth](https://wordpress.org/support/users/alchymyth/) … brilliant, thanks!
   Works like a charm.
 * Do you know hoe to add things like “only category 5” or “only posts tagged ‘whatever'”?
 * Is that some part of the $wp_query thing?
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/really-basic-loop-php-question/#post-2527709)
 * > Do you know hoe to add things like “only category 5” or “only posts tagged ‘
   > whatever'” ?
 * for the whole loop?
    see [http://codex.wordpress.org/Function_Reference/query_posts](http://codex.wordpress.org/Function_Reference/query_posts)
   [http://codex.wordpress.org/Class_Reference/WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query)
   [http://codex.wordpress.org/Class_Reference/WP_Query#Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Parameters)
 * or for individual posts in the loop?
    see [http://codex.wordpress.org/Conditional_Tags](http://codex.wordpress.org/Conditional_Tags)

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

The topic ‘Really basic "loop" PHP question…’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/really-basic-loop-php-question/#post-2527709)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
