WordPress.org

Forums

different format for most recent entry (7 posts)

  1. fodden
    Member
    Posted 7 years ago #

    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.

  2. microkid
    Member
    Posted 7 years ago #

    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>
  3. fodden
    Member
    Posted 7 years ago #

    Thanks, Microkid. That's really helpful.

  4. fodden
    Member
    Posted 7 years ago #

    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++

  5. Root
    Member
    Posted 7 years ago #

    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.

  6. microkid
    Member
    Posted 7 years ago #

    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.

  7. Root
    Member
    Posted 7 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags