WordPress.org

Support

Support » Themes and Templates » different format for most recent entry

different format for most recent entry

  • Is there a way to have the most recent post formatted differently from all of the rest?

    I’d prefer it if I didn’t have to use two loops.

    I’ve searched as best I can; sorry if I’ve missed something obvious.

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • microkid
    Member

    @microkid

    Sure, you’ll have to edit your template.

    You could add something like this to your loop:

    <psuedocode>
    
    $n = 0;
    loop {
    
       if( $n == 0 ) {
          // format 1st post
       }
       else {
          // format other posts
       }
    
       $n++;
    }
    
    </psuedocode>

    Thanks, Microkid. That’s really helpful.

    Would something like this work?

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
     <?php if ( $n == 0 && is_home ()  ) { ?>
               <div class="top_post">
     <?php } else { ?>
               <div class="post">
     <?php } ?>

    I wasn’t sure from your answer, Microkid, how I was to include the $n=0 and the $n++

    I have been thinking recently that if we put our posts in an ordered list we could style them all individually using n: child etc.

    microkid
    Member

    @microkid

    Like this:

    $n = 0
    
    loop { 
    
       if( $n == 0 ) show first_post format
    
       else show regular post format
    
       add 1 to $n so i know i've had the 1st
    
    }

    Root: it would be cool to have the option in the shape of a parameter “list_style=ol” passed to have_posts() or something.

    I wasn’t thinking of the php. I was just thinking add an ol in the index.php for our posts. Then use CSS. No php hackery is needed.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘different format for most recent entry’ is closed to new replies.