Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am working on my category template. Here is how I want the page to display:

  1. Category Name - this is done
  2. The latest post for each category be on top (then styled which I can do).
  3. The Category description - this is done
  4. List all the rest of the posts for the category under it - I can list all the posts, but I want to skip the latest

Any help in pointing me in the right direction, I would appreciate it. Thanks

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Use WP_Query's built in current_post counter in your loop:

while( have_posts() ):
    the_post();
    if( $wp_query->current_post == 0 ):
        // this is the first post in the loop
    else:
        // this is > first post
    endif;
endwhile;

EDIT w/html:

<?php
while( have_posts() ):
    the_post();
    if( $wp_query->current_post == 0 ):
        ?>
        featured post

        category description

        <ul>
        <?php
    else:
        ?>
        <li>post</li>
        <?php
    endif;
endwhile;
?>
</ul>
share|improve this answer
    
How does that work with putting code in between? I want to put the description after the first post and an ul list around the n+1 posts. –  Martin May 7 '12 at 16:38
    
@Martin see edit above –  Milo May 7 '12 at 16:49

Create a $counter variable (that equals 0 at the beginning) outside of the posts loop. Increment the variable by 1 in the loop. Again, inside the loop check if the counter is 0, if yes - do nothing, if it's bigger than 0 - show the post. :)

share|improve this answer
    
Show how do I get the latest post for the category? Run the loop twice? –  Martin May 7 '12 at 15:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.