• Resolved srpd

    (@srpd)


    Hi, i’m searching for a function to call the last blog post. Not last in the page but last one posted, the most recent. Is that possible?
    Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter srpd

    (@srpd)

    how can i use it…
    i would do something like this:

    if (last_post) {
    echo welcome;
    }else{
    echo bye;
    }

    Probably a better alternative:

    $my_query = new WP_Query('posts_per_page=1');
    if ($my_query->have_posts()) {
       while ($my_query->have_posts()) { $my_query->the_post();
         // Do stuff with the post;
       }
    } else {
       // Do stuff for no post;
    }
    Thread Starter srpd

    (@srpd)

    uhmmmm but in this why there is a problem…
    for example, i have my homepage, i set to show 20 post for page and posts are 40. I’m searching to show the most recent post with a style and more 39 post with another style, but i’m not able to find how to call this function….

    Sorry, that is a different question. I can’t test this, but it should give you a start. I am assuming you have a loop like this:

    <?php while ( have_posts() ) : the_post() ?>
       // Do stuff with the post;
    <?php endwhile; ?>

    Alter it like this:

    <?php $c = 0; ?>
    <?php while ( have_posts() ) : the_post() ?>
       <?php if ( !is_paged() && ++$c == 1 ) { ?>
          // Do stuff with the first post;
       <?php } else { ?>
          // Do stuff with other posts;
       <?php } //endif; ?>
    <?php endwhile; ?>
    Thread Starter srpd

    (@srpd)

    fantastic… it works, thanks so much man 🙂

    You’re welcome. Please mark this topic ‘Resolved’.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to define last post’ is closed to new replies.