• Resolved andreu

    (@andreu)


    Hi.

    I’d like to change de CSS of the last post of a day. I’m listing my posts grouped by date, showing the date once a day, not in all the posts.
    I’ve been searching around docs and support forums and I didn’t find anything similar. I’ve only found how to determine the last post of a page, but it’s not the same.

    Any suggestions?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Which order are you displaying your posts? Newest (latest) first or oldest first

    If newest first, isn’t the last post of the day the very first post you are displaying?

    Also, are you trying to style the display of the last post for each day? Meaning the last post for today, and the last post for yesterday, and so on…

    Thread Starter andreu

    (@andreu)

    Hi MichaelH.

    I’m displaying the oldest first, so it’s not the first post I’m displaying that changes the style (it’s the first post only if the day have one single post).
    Yes, i want the last posts of each day displays different from the rest.

    Any ideas now?
    Thank you! ??

    Well if you were showing posts in the order of newest to oldest date that would be easy to accomplish. The problem is determining if a post is the LAST one for a given date. Essentially that means, before you display a post, you need to know if the NEXT post is a different date.

    So in your loop, do a query to get one post ID for the date of the current post, and if that result is the same post ID as the current post then you know the current post is also the last post of that date:

    <?php
    $cpd=mysql2date('Ymd', $post->post_date);
    $just_one=get_posts('year=' .substr($cpd, 0, 4) .'&monthnum=' .substr($cpd, 4, 2) .'&day=' .substr($cpd, 6, 2) .'&showposts=1&order=DESC');
    if( $just_one) {
      $latest_ID=$just_one[0]->ID;
    }
    if( ($latest_ID == $post->ID) ) {
      echo 'this is the latest post for this date';
    }
    ?>

    Thread Starter andreu

    (@andreu)

    Hi.

    Your code works for the first post of the date, but not for the last one. After analysing it I tried some changes and finally I get the clue, the order of the query get_posts should be ASC, not DESC.

    Anyway, thank you a lot for your time ??

    Not sure I understand – the overall order of your posts shouold be in ASC (ascending) order, but the code I described should be using DESC because it is looking for the latest post (1 post) for that date.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Knowing the last of the day in the loop?’ is closed to new replies.