WordPress.org

Ready to get started?Download WordPress

Forums

is_single get the lasted post (3 posts)

  1. Anonymous
    Unregistered
    Posted 6 years ago #

    I am using a a little menu for the lasted post on my single pages. I just want to have the first excluded from this list, if the single page displays the lasted post.

    I am currently doing this by hand:

    <?php
    global $post;
    if (is_single('239')) {
    $posts = get_posts('numberposts=4&offset=1');
    } else {
    $posts = get_posts('numberposts=4&offset=0');
    };
    foreach($posts as $post) :
    setup_postdata($post);
    ?>

    Is there any way like
    is_single(lastest_post)

    ???

  2. ikiru
    Member
    Posted 6 years ago #

    I'm not 100% sure of what you're trying to do, but it seems like you could do this with the $do_not_duplicate technique offered in this explanation of The Loop.

    You'd essentially modify the original loop on single.php to include $do_not_duplicate = post->ID; and then make your next loop excludes $do_not_duplicate. I don't feel like writing out and testing the thing, but it seems like it would do what you want.

  3. seej
    Member
    Posted 6 years ago #

    This might help:

    <?php
          $i=0; // Initialize to Zero;
          if (have_posts()) :
            while (have_posts()) : the_post();
                if ($i==0) {$recentpostid = $post->ID; $i=$i+1;}
            endwhile;
          endif;
          //get only the latest post
          $posts = query_posts( 'p='.$recentpostid."'");
    ?>
    <?php echo $recentpostid ;?>

    (from another thread)

    I'm trying something similar. I have a list of posts, and one displayed. Without reloading the page, I want to be able to click the next post title, and have it displayed. So far so good with an iframe. However, I can't get my single.php that's my iframe to load initially with the latest post. Let me know if you figured this out.

    Best, seej

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags