• Resolved surfsup74

    (@surfsup74)


    I am trying to work out how to get the last part of the url (following the final slash) and then insert it inside a piece of php in the attachment template that is used to display content on the next page I arrive at.

    Say I’m looking at a ‘gallery’ page with all the images I’ve tagged ‘Cornwall’ – the url will be domain.co.uk/archive/photographs/cornwall. If I click an image on that ‘gallery’ page I go to a page showing that image (eg. domain/house-in-cornwall. The the new page I arrive at to view the image doesn’t know which ‘gallery’ ‘tag’ page I have come from (my images could have multiple tags ‘property’, cornwall, interior etc) and so the navigation on that image page doesn’t currently work properly. The next/prev links just go through the images in the order they were uploaded to my site.

    I want the next/prev links to go to the next/prev image that has the same tag as the gallery page I came from. I can do this if I can get just that last part of the url (the taxonomy term) and somehow add it dynamically to the template file that displays the ‘image’ page and keep using it until the user leaves and goes to another ‘gallery’ page – say… ‘Portraits’ at which point that final part of the url (portraits) is remembered and used in the next image pages and so on…

    The gallery pages urls will all be domain.co.uk/archive/photographs/then_tag_name_to_remember_here. This may be useful to know for the remembering bit. Maybe the last word in the url is remembered whilst on ‘image’ pages only until a ‘gallery’ page /archive/photographs/… is visited again at which point the memory expires and new last word (taxonomy term) is stored and used?

    I would have thought this is possible?

Viewing 1 replies (of 1 total)
  • Thread Starter surfsup74

    (@surfsup74)

    I have solved this now.

    I used this to get the last part of the url (the taxonomy term)

    $url = $_SERVER['REQUEST_URI'];
    $url = trim($url, '/');
    $array = explode('/',$url);
    $the_taxterm = end($array);
    echo $the_taxterm;

    Then this to store it.

    session_start();
    $_SESSION['the_taxterm'] = $the_taxterm;
    echo $the_taxterm;

    And this to use it in the image template

    session_start();
    $the_taxterm = $_SESSION['the_taxterm'];
    echo $the_taxterm;

    I didn’t need to worry about the expire bit as it seemed to expire / refresh anyway.

Viewing 1 replies (of 1 total)
  • The topic ‘Remember taxonomy term and use it to restrict subsequent attachment page nav’ is closed to new replies.