WordPress.org

Ready to get started?Download WordPress

Forums

Customize Last Post (3 posts)

  1. miniimage
    Member
    Posted 5 years ago #

    Is there a way so I can style only the last post? I know that I can style a post by post IDs but I want to style generally all the last post.

  2. MichaelH
    Member
    Posted 5 years ago #

    Just use a counter to figure that last post, which on a WordPress blog means the latest (or first post displayed).

    <?php
    $count = 0;
    if (have_posts()) {
     while (have_posts()) : the_post();
      $count++;
        if ($count <= 1) {
    //your special stuff
          the_content();
        } else {
          the_content();
        }
     endwhile;
    }
    ?>
  3. miniimage
    Member
    Posted 5 years ago #

    So how do I go about on inserting that? I just insert that code? I know you said that's for the first post, but the maximum posts per page on my blog is 10.

    Should I do something like this:

    <div class="lastpost">
    
    <?php
    $count = 10;
    if (have_posts()) {
     while (have_posts()) : the_post();
      $count++;
        if ($count <= 10) {
    //your special stuff
          the_content();
        } else {
          the_content();
        }
     endwhile;
    }
    ?>
    
    </div>

    Oh, and thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags