WordPress.org

Ready to get started?Download WordPress

Forums

using get_posts() always show the same post (4 posts)

  1. sooeydoo
    Member
    Posted 8 years ago #

    I'm trying to put the get_posts function in the header template to call posts 9-16 by using this:

      <?php
      $posts = get_posts('numberposts=8&offset=8');
      foreach ($posts as $post):
      setup_postdata($post);
      ?>

    • "><?php the_title() ?>
    • <?php endforeach; ?>

    It works well, but the problem is when I use it, no matter which post I'm clicking on it always shows the 9th most recent post (the number of posts that I have offset get_posts by).

    Though the title in the browser displays correctly as the title of the post I clicked on, the Post title and post content displayed on the page always belongs to the 9th most recent post.

    Please help me on how I can avoid this...

  2. moshu
    Member
    Posted 8 years ago #

    I am not sure... just a thought. Why do you put the code in the header.php? Since the same header is called for everything, maybe the offset is in effect on every page of yours.
    What if you move the code to the index.php or wherever you want to use it?

  3. sooeydoo
    Member
    Posted 8 years ago #

    I just tried that by including the code in single.php, but again it keeps showing the same post on every post's page. But this time it shows the 16th post instead of the 9th.

    I put it on the header because I want to put a three column table in the header before the sidebar splits the page into two. One column would have the most recent 8 posts which I call using get_archives(postbypost), and a second column would have the posts 9-16 which is what I'm trying to call using get_posts.

    So, I'd prefer using it in the header.

  4. sooeydoo
    Member
    Posted 8 years ago #

    Anybody has any clue why this is happening? Help would be much appreciated indeed.

Topic Closed

This topic has been closed to new replies.

About this Topic