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 have a custom post-type 'videos' and on the first page I have the first video styled differently than the next videos on the page. Basically I show the first video in a large format, while the rest of the videos on the page are small.

Question:

On page 2, 3, etc of the video post-type, I do not want to have a large video on the top of the page, but rather follow my standard styling.

What would be the best way to do this?

Currently I am using rewrite rules to allow me a second template page for my 'paged' for the post-type. I would rather not use this approach anymore as it is more to maintain.

If I used a check like if_paged.. then I find that I have to replicate a ton of code on my template. Hoping there is a simple way to identify the first post in the loop, style that, and then continue... open to any ideas

thanks

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

In response to your comment, $wp_query->current_post in action. Note that it's zero-indexed:

<?php

if (have_posts()) :
while (have_posts()) : the_post();

    if($wp_query->current_post==0):
        echo "this is the first post";
    else:
        echo "this is post number " . ($wp_query->current_post + 1);
    endif;

endwhile;
endif;

?>
share|improve this answer
    
Thank you, learned something new today! Love those kind of days –  shawn Jun 4 '11 at 23:54
    
thanks - a great way to get rid of that counter. imgo, this would still need to be combined with is_paged() get achieve the aim of the original question. –  Michael Jun 5 '11 at 9:59
add comment

i don't think there is anything easier than to use the is_paged() together with a counter;

before the loop: <?php $counter = 1; ?>

in the loop:

<?php if( $counter == 1  && !is_paged() ) : 
$counter++; ?>
/*code for the first post with large video*/
<?php else : ?>
/*code for all other posts*/
<?php endif; ?> 

the amount of duplicated code obviously depends on the existing structure of the loop.

share|improve this answer
1  
or use the global $wp_query->current_post to check where you are in the loop. –  Milo Jun 4 '11 at 20:48
    
@Milo I have not seen this concept before. Do you have a snippet example of how this would work? While I understand Michael's snippet, I am always looking to learn new things. –  shawn Jun 4 '11 at 22:55
    
@shawn - I posted an example. –  Milo Jun 4 '11 at 23:47
add comment

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.