WordPress.org

Ready to get started?Download WordPress

Forums

Style oldest post (2 posts)

  1. tmyie
    Member
    Posted 1 year ago #

    I've managed to find a loop that targets both the *latest* post, as well as the *rest* of the content. However, I need to find a loop that can style the *last* post.

    Would anyone know how this is done?

  2. vtxyzzy
    Member
    Posted 1 year ago #

    You can do this by saving the ID of the last post on the current page and the max number of pages and then compare those to the current values for each post. Here is some sample code:

    if (have_posts()) :
       $last_post = end($wp_query->posts);
       $last_id = $last_post->ID;
       $last_page = $wp_query->max_num_pages;
       while (have_posts()) :
          the_post();
          if ($last_page == $paged && $post->ID == $last_id) :
             // Put special code for last page here
          endif;
          // Rest of loop code here
       endwhile;
    endif;

Topic Closed

This topic has been closed to new replies.

About this Topic