Support » Requests and Feedback » keep previous/next post query the same as main query

  • mmatty


    In y blog, when a user enters a single post page (a permalink) he is also presented with a next post/previous post links (Using the next_post_link/previous_post_link tags).

    My problem is that those tags will not account for the context the user arrived from. There could be 4 different
    types of those:

    1. User came from default index page – in this case next/previous works correctly (phew..)

    2. If the user came from a category page (showing just the posts in a particular category) then the next/previous post should only relate to that category.

    3. If the user came from a search result page, the next/previous should navigate in the results space and not the entire posts space.

    4. If the user chose a different sorting order (I allow sorting the index page by post ratings), then next/previous should respect the sorting order.

    Is there a way for me to keep and re-use the query from the last page, and use that to figure out what are the next and previous posts?

Viewing 2 replies - 1 through 2 (of 2 total)
  • microkid


    I think it could be possible in your templates.

    Something like

    <pseudo code>
    <?php if( is_search() ) : ?> get_next_search_result <? elseif ( is_archive() ?> get_next_archive_post <? etc.. ?>
    </pseudo code>



    If anyone interested, here is the solution I came up with for the category case (#2 in my list):
    On the index page I check is_category()
    if it’s true (Im inside a category page) then whenever I have a permalink to a single post page, I would append “?fromCat=xx” (xx being the current category)

    In the single (permalink) page I check $_GET[‘fromcat’], and if it exists, this means I have to modify my next_post_link so it will only look in category xx.

    Then its pretty much the same for the other things I asked.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘keep previous/next post query the same as main query’ is closed to new replies.