is_single get the lasted post (3 posts)

  1. Anonymous
    Posted 8 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:

    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) :

    Is there any way like


  2. ikiru
    Posted 8 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
    Posted 8 years ago #

    This might help:

          $i=0; // Initialize to Zero;
          if (have_posts()) :
            while (have_posts()) : the_post();
                if ($i==0) {$recentpostid = $post->ID; $i=$i+1;}
          //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