Return to Browse

Is there anything in LinkFunctions.php that would help me construct a link from the items/show page back to the specific page in items/browse that contains the item I am currently showing. In other words, I want to add another link following my next/previous links that says "Return to Browse". This link wouldn't go to the beginning of the browse, but rather to the specific browse page that contains the item I was just looking at (even if that is a different item from the one I originally clicked on in the browse screen because I have been using next/previous to step through some items from my current browse context).

Note that I have already implemented a custom next/previous to step through a search, a single collection, or the list of recent items from the home page (in addition to the usual browse all). So my next/previous function already knows the context for the current item, including its id and it's position in the get_items list for that context. Do I need to calculate a page number somehow and build the url for the "Return to Browse" from scratch?

Assuming your browse pages display ten items at a time, you could probably get a browse page number by dividing the $key in your custom next/previous function by the number 10, and then rounding up using ceil. If you are within your search results on an item show page, and the item happens to be the 55th item in the group, then the corresponding browse page would be 6. So 55/10 rounded up to the nearest whole number equals 6.


Then from there I think you could create a link back to the browse items:

$returnbrowse= '' .  $browsepage .'?'. $_SERVER['QUERY_STRING'];
echo '<a href="'.html_escape($returnbrowse).'">Return to Browse</a>';

I haven't tested this but I think it could work. The only issues I can imagine is the $key not working properly in the ciel(), or the $_SERVER['QUERY_STRING'] not working on an items/show page.

Thanks Andy. I'll try working with that and see where it goes. I have already added the query parms (including any search terms or the collection id) to the urls that link to the items/show page since I use those to make sure my next/previous function steps through the right list of items no matter how the user gets to items/show.

I just want to confirm that the approach suggested by Andy does work.

First, calculate:

$page = ceil($key + 1 / 10);

Then, build the base url:

$url = WEB_ROOT . '/items/index/page/' . $page;

Then, append any query parms you need to that base url, wrap the result in html, and you have a working link from the items/show page back to the item's location in items/browse (at least in the minimalist theme I am customizing).

Thanks, Andy!

This, and Paul's customized next/previous code, sound like great candidates for a recipe page!

Cool glad it works!