[wp-hackers]Treat most recent post differently to the rest

Alan Castonguay alan at verselogic.net
Fri Jan 16 00:55:47 GMT 2009


To combine these, you can also do something like this;

<?php
if( have_posts() ) :

the_post();
?>
DOING SOMETHING WEIRD TO THE MOST RECENT POST HERE
<?php

while (have_posts()) : the_post(); ?>
OUTPUTTING THE REST NORMALLY HERE
<?php endwhile;

endif; ?>


Alan J Castonguay


-------------- next part --------------


On Jan 14, 2009, at 7:42 PM, Glenn Ansley wrote:

> I've done this before by just testing for the loop count. $wp_query
> has this built in. The first post in the loop is 0
> global $wp_query;
> if ( $wp_query->current_post === 0 ) {
>   // style for first
> }else{
>  // style for the rest
> }
>
> http://codex.wordpress.org/Function_Reference/WP_Query
>
> On Wed, Jan 14, 2009 at 7:15 PM, Alex Hempton-Smith
> <hempsworth at googlemail.com> wrote:
>> Hi all,
>> On my category archives page, I'm outputting the first post into a  
>> different
>> HTML structure, and then outputting the rest of them below that as  
>> normal.
>>
>> <?php
>> $recentPosts = new WP_Query();
>> $recentPosts->query('showposts=1');
>>
>> while ($recentPosts->have_posts()) : $recentPosts->the_post();
>> ?>
>> DOING SOMETHING WEIRD TO THE MOST RECENT POST HERE
>> <?php
>> endwhile;
>>
>> while (have_posts()) : the_post(); ?>
>> OUTPUTTING THE REST NORMALLY HERE
>> <?php endwhile; ?>
>>
>> Because I've already outputted that most recent post, how do I  
>> exclude it
>> from the main output below that?
>> Almost like offset the output to start 1 post later than the most  
>> recent
>> ones.
>>
>> Hope this makes sense :)
>>
>> Many thanks,
>> -- Alex
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list