Forums

Retrieve adjacent posts query (5 posts)

  1. lostmodern3d
    Member
    Posted 8 months ago #

    Hi

    My theme (Imbalance) retrieves 2 featured posts in the sidebar with :

    query_posts("showposts=2&offset=1");

    but it always calls the 2 same featured posts.

    Is there a way to adjust the query to retrieve the adjacent (previous and next) posts in the same category?

  2. lostmodern3d
    Member
    Posted 8 months ago #

    the full php string might be useful

    <?php
    wp_reset_query();
    query_posts("showposts=2&offset=1");
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    thanks

  3. esmi
    Theme Diva & Forum Moderator
    Posted 8 months ago #

    Is there a way to adjust the query to retrieve the adjacent (previous and next) posts in the same category?

    Nope - but you could randomize the post order.

    <?php
    wp_reset_query();
    query_posts("posts_per_page=2&offset=1&orderby=rand");
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  4. lostmodern3d
    Member
    Posted 8 months ago #

    Thanks esmi for the fast suggestion.
    There must be a way to call the adjacent post, plugins like post navigation do it.
    query_posts() is maybe not the best solution, what about wp_query() or get_adjacent_post()?
    But randomizing is a really cool idea, even maybe better.

  5. esmi
    Theme Diva & Forum Moderator
    Posted 8 months ago #

    In theory, it is possible to grab the previous and next posts but I think it would mean running 2 extra queries just for that - which you might want to have a think about first.

Reply

You must log in to post.

About this Topic