• 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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter lostmodern3d

    (@lostmodern3d)

    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

    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(); ?>
    Thread Starter lostmodern3d

    (@lostmodern3d)

    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.

    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.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Retrieve adjacent posts query’ is closed to new replies.