Is it possible to filter prev/next buttons to only go through entries which are tagged with the current page’s active tag? I’m making a portfolio site for my paintings, and the main gallery categories are filtered by tags (portraits, landscapes, still-lifes, etc.). I’ve managed to make it so that if someone clicks on a painting when the portfolio page is actively filtered by a tag (say portraits), then it links to the specific project page with the tag still active:
siteurl/portfolio/tag:portraits/project-slug
On this page, would it be possible to have the nex/prev buttons only pull from projects tagged as “portraits”?
I used tags here instead of grouping my paintings into subfolders within the portfolio folder because many painting fall into multiple categories.
Thanks! I was just looking at that. Unfortunately, my php and Kirby skills are barely above cut and paste. If @AudioBear’s plugin can be used to do what I’m looking for, I’m not sure how.
Not sure if this is what you want, but you can use a paginated array of pages / tags, in the demo Articles tagged ‘Law’ or if you don’t want the detail pages in the demo, Press tagged ‘Social+Media’.
You are basically going to have to set up you index pages as per the usual ‘article’ page examples for use with/out tags in the URL’s, see docs.
Assuming you have paginated array of the articles, these bits of code (not complete and untested) are an example for if tags are set in the URL. You also need code for it tags aren’t in URL):
// page template
// If any tags are set...
if(urldecode(param('tag'))) {
// Get our array of articles
$articles = $pages->find('articles')
->children()
->visible()
->filterBy('tags', urldecode(param('tag')), ',')
->sortby('date', 'asc')
->flip()
->paginate(3);
// Do some pagination
$pagination = $articles->pagination();
//Call uniNextPrev plugin with pagination
$uniNextPrev = uninextprev(array('pagination' => $articles->pagination()));
//..... some more code for when tags are not set and other stuff you might need.
));
// Then we are going to call our footer snippet with the uniNextPrev variables
snippet('footer', array(
'nextPageURL' => $uniNextPrev['nextPageURL'],
'nextPageTitle' => $uniNextPrev['nextPageTitle'],
'prevPageURL' => $uniNextPrev['prevPageURL'],
'prevPageTitle' => $uniNextPrev['prevPageTitle']
))
In the footer snippet we would have some code… something like this
Thanks, I really appreciate the response. I installed your plugin and am experimenting now…
In your example, I would want to click on an article tagged ‘Law’, and then on the article detail page, I would want the next/prev buttons to only cycle through articles tagged ‘Law’.
From the your Articles tagged ‘Law’ page, I would be able to force the tag ‘Law’ into the detail pages, like this:
But then I would need to filter the prev/next buttons for the detail page’s active tag (‘Law’).
In the end, I didn’t use $page->next() or @AudioBear’s plugin. The gist of what I came up with is pasted below, in case it is of use to anyone. (I’m sure it could be done much more elegantly, but I’m just happy that it works). Also, this is now live on my website: http://jqdaily.com/portfolio/tag:figures
@AudioBear – thank you so much for your reply! It put me on the path to this solution.