Support » Plugin: Ambrosite Next/Previous Post Link Plus » Adapting for a "View All" page

  • Resolved tokyobear


    Sorry, second question in as many hours. I couldn’t see anything related to this question is the forums so would just appreciate a pointer…

    I have a custom post (portfolio) within which I have various categories (landscapes, seascapes, and so forth). On my main page clicking on any of these categories takes me to a page which generates thumbnails for all the posts in that category. Clicking on any of these images takes me to the single-portfolio.php where I use your plugin — and it works perfectly at cycling through the images in each category.

    However, on my main page I also have a “View All” link which generates ALL thumbnails in my ‘portfolio’ regardless of category. Clicking on an image from here will eventually use the same single-portfolio.php and so the previous/next post links will cycle through the category of whichever image I happened to click — not just the next one in that custom post.

    Will try and solve this myself but since it must be a common issue I was hoping you might be able to give me a quick pointer to start me in the right direction?

    Thanks once again.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author ambrosite


    Yes, it is a common question, but unfortunately there is no simple solution. Basically you would need to use PHP sessions to track which link a user clicked on some previous page, and then set up a conditional based on the session variables to generate the appropriate link navigation. There is some sample code given in this thread, in case you want to try hacking it together yourself:

    Fairly new to all this but I’ll take a shot!

    Thanks again for the prompt response!

    Just in case anyone else has this same problem, I thought I’d submit my solution. This thread, as pointed to by ambrosite, was a great starting point and may well be the solution for many.

    For me it wouldn’t work because I didn’t have a parent category; I had a custom post (‘portfolio’) and then a number of categories/groups (‘landscape’, ‘coastal’, and so on).

    Anyway, in functions.php as per the thread above:

    function init_sessions() {
        if (!session_id()) {
    add_action('init', 'init_sessions')

    In the footer (just above wp_footer()):

    if ($_GET['group']==FALSE) {
    $_SESSION['history'] = "ViewAll"; }
    else {
    $_SESSION['history'] = "Group";}
    if ($_SESSION['history'] == "Group") {
    elseif ($_GET['portfolio']==FALSE) {

    And in my single.php:

    if ($_SESSION['history'] == "Group" || $_SESSION['myVar'] == "Group") {
    next_post_link_plus(in_same_tax set to TRUE)
    previous_post_link_plus(in_same_tax set to TRUE)
    else {
    next_post_link_plus(in_same_tax set to FALSE)
    previous_post_link_plus(in_same_tax set to FALSE)}

    The code basically pulls the variable from the previous URL so it knows that you clicked on ‘image1’ by coming through ‘Coastal’ and not ‘View All’. The problem is that this refreshes as you click through the next post — in other words the computer doesn’t know whether you got to ‘image2’ by going… ‘Coastal’ –> ‘Image1’ –> ‘Image2’ OR ‘View All’ –> ‘Image1’ –> ‘Image2’

    That’s why I set the MyVar to ‘Group’ as soon as $_SESSION[‘history’] == “Group” (hence the OR statement in single.php).

    elseif ($_GET['portfolio']==FALSE) {

    The above code is included so that if the user clicks on another other page (I have links to featured images in the sidebar) then myVar is changed and if the user clicks on ‘image1’ from the sidebar then he will enter the general loop…(URL for single images is ?portfolio=image1)

    I guess this solution doesn’t work if you change the permalinks from the default setting in WP (since I’m using $_GET) but it’s one way round the problem so I thought I’d post…

    I think this solution also enables you to select more than one category, as well — I haven’t tried but I don’t immediately see an issue.

    Plugin Author ambrosite


    Congratulations! You may be new at this but you managed to get it working. Thanks for sharing your code; I will add this thread to my list of examples for when this question comes up in the future.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adapting for a "View All" page’ is closed to new replies.