Hi everyone,
I would like to add a link in my item site show.phtml that takes users back to the results page of their last search.
I’ve seen that this feature is built into BlockPlus (GitHub - Daniel-KM/Omeka-S-module-BlockPlus: Module for Omeka S that adds some new blocks for the static pages and improve some of the existing ones.), but I don’t understand what I need to do to get the Back to last search link to show up for me
I was able to integrate the Next and Back arrows into show.phtml without any problems, but I just can’t get the Last browse page to work
I am using the Foundation theme.
If anyone knows what to do here: I am grateful for any help
Thank you for all the amazing work you are doing!
Hello again ,
I thought about the problem again and wondered if there might even be a “fairly simple” way. What I would like to have is the ability to go back to the results list of a search after selecting an item from the search list.
I am using the Advanced Search module with the internal sql search engine. My search page runs under the URL xyz.org/search, i.e. search queries run via search?q=…
Would it be possible to save this query in a variable, for example, and integrate it as a back button in the item view “show.phtml”?
Oh dear, I hope I have expressed myself reasonably clearly - I am still a complete newbie and am taking my first steps in PHP. Any help is greatly appreciated.
Many thanks in advance!!! The forum is great, I’ve already found so many helpful tips here! THANK YOU.
Hi @esrapaul ,
I might approach this a little differently.
In the show.phtml I would add the following snippet which checks the referrer and shows the back button if it contains “/search”. Then, rather then trying to recreate the search, you simply use the browser history to go back to the previous page.
<?php if (strpos($_SERVER['HTTP_REFERER'] ?? '', '/search') !== false): ?>
<button id="back-button" onclick="window.history.back()">Back</button>
<?php endif; ?>
Hey @fackrellj,
1000 thanks for your answer! I was very pleased and installed your code straight away. It works wonderfully! Wow!
I was wondering if there was such a possibility for the following scenario: Assuming my search brings up more than one search result and I select an object from the list, then get to the single view (show.phtml) and have the possibility to navigate to the next or previous object from the search list via next or previous arrows. I look at, let’s say, three objects and then want to return to the search list. Then the back button does not work because the previous page is not the search results page. Is there a way to do this? So that I somehow save the entire q-string of the search results page and create a back button from it?
Maybe that’s too complicated - as I said, I don’t really know anything about PHP yet.
Either way: many, many thanks for your suggestion, it’s definitely great - and it’s not the first time you’ve helped me
Thank you very much!
@esrapaul ,
You could try this variation. Here were are checking the existence of “/search” and setting a session variable to the referrer. Then checking for the session variable and using that value to create a link back to the search page.
This might work better for what you want, but I could see it being a little confusing if someone does a search, navigates to an item, then goes somewhere else on the site (e.g. the browse page) and then to another item, the “Back” button would take them to the previous search results. But, then again, this approach could also be considered a feature. Either way I think it solves the problem you’re talking about of easily getting them back to the search results if they happen to use the “Next” of “Previous” buttons.
<?php
if((strpos($_SERVER['HTTP_REFERER'] ?? '', '/search') !== false)){
$_SESSION['search'] = $_SERVER['HTTP_REFERER'];
}
?>
<?php if (! empty($_SESSION['search'])): ?>
<a id="back-button" href="<?php echo $_SESSION['search']; ?>">Back</a>
<?php endif; ?>
Hey @fackrellj,
OMG! You are brilliant!!! This is exactly what I wanted Thank you so much! It works perfectly. Hooray!!!
<3 for your help and your time!
1 Like