# Gallery according taxonomy - next/previous buttons

**URL:** <https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951>\
**Category:** Uncategorized\
**Created:** [September 10, 2020, 12:27pm UTC](https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951 "2020-09-10T12:27:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpc](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/jpc/32/2643_2.png) [@jpc](https://talk.jekyllrb.com/u/jpc)\
**Post date:** [September 10, 2020, 12:27pm UTC](https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951/1 "2020-09-10T12:27:57Z")

</div>

Hello,  
As @mmistakes suggested me I created a gallery according the category.  
I created a my\_gallery.md page and added in the yaml:

```auto
---
title: Foo
layout: category
permalink: /category/foo/
taxonomy: foo
entries_layout: grid
---

```

my\_gallery display all posts with the foo category.

But …  
The previous/posts buttons don’t scan ONLY the posts of the foo category ! They scan ALL posts !!

What is missing ?  
Shall I developp a new layout or a new include ?

As the posts use single.html by default, that seems complicated ?

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [September 10, 2020, 1:59pm UTC](https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951/2 "2020-09-10T13:59:24Z")

</div>

What does your Liquid logic look like for the next/previous buttons?  
Out of the box those apply to **all posts**. You’ll need to add some logic to check the current category and filter out just those posts so it’s going to the next/previous post in X category.

---

<div class="post-metadata">

**Author:** ![jpc](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/jpc/32/2643_2.png) [@jpc](https://talk.jekyllrb.com/u/jpc)\
**Post date:** [September 10, 2020, 4:48pm UTC](https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951/3 "2020-09-10T16:48:39Z")

</div>

Yes but all posts use “single.html”. It should that the list of posts use another “single.html” and change the logic of the next/previous buttons. That means the default defined in \_config.yml should not be used, etc …  
Am I wrong ?

Two single.html: one standard and one special for list ?  
To pass a switch (a global parameter) to the archive-single.html module  
Is it possible to change dynamically the layout of the posts ?

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [September 10, 2020, 7:02pm UTC](https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951/4 "2020-09-10T19:02:16Z")

</div>

`_layout/single.html` has an include for post pagination, the (next/previous) links. That code is here:

> <https://github.com/mmistakes/minimal-mistakes/blob/master/_includes/post_pagination.html>

This uses Jekyll’s `page.previous` and `page.next` variables, which coming from the [Jekyll docs](https://jekyllrb.com/docs/variables/) are:

> `page.next` The next post relative to the position of the current post in `site.posts` . Returns `nil` for the last entry.
> 
> `page.previous` The previous post relative to the position of the current post in `site.posts` . Returns `nil` for the first entry.

If you want to only show the previous and next document in a collection or some other sort of array that **isn’t** all posts, then you need to modify that code. You will need some Liquid code to check the current collection, taxonomy, tag, category, whatever and then filter those documents out of `site.posts`, then determine what the next and previous item is.

I believe there are plugins that do this as well if you don’t want to go the Liquid route, as I seem to remember some performance implications when doing it as you need to loop through all documents on each page. And that isn’t a great idea if you have a large site.

---

<div class="post-metadata">

**Author:** ![jpc](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/jpc/32/2643_2.png) [@jpc](https://talk.jekyllrb.com/u/jpc)\
**Post date:** [September 22, 2020, 2:28pm UTC](https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951/5 "2020-09-22T14:28:48Z")

</div>

I guess the code I must write BUT I don’t see how to “say” to the single.html module or to the post\_pagination module that the context is a selection, not a normal context.

In pseudo language:  
if context=selection then execute my code else execute the Mikael’s code

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [September 22, 2020, 2:50pm UTC](https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951/6 "2020-09-22T14:50:50Z")

</div>

I used this on my personal site to do next/previous links. It would check the page’s collection, then filter out the next/previous document in the same collection.

I stopped using it because it was extremely costly and increased my build times considerably.

> <https://gist.github.com/mmistakes/43a355923921d22cd993>

---

<div class="post-metadata">

**Author:** ![jpc](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/jpc/32/2643_2.png) [@jpc](https://talk.jekyllrb.com/u/jpc)\
**Post date:** [September 22, 2020, 3:01pm UTC](https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951/7 "2020-09-22T15:01:41Z")

</div>

The key is page.collection  
That could be page.categories ?

I must definitively learn Jekyll and Liquid !

Is it possible to put a breakpoint in post\_pagination and to test expressions ?

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [September 22, 2020, 5:00pm UTC](https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951/8 "2020-09-22T17:00:27Z")

</div>

In theory yes, but you’ll need to make modifications.  
This method likely falls apart if you assign posts to multiple categories, which will complicate things.

And not sure on Liquid breakpoints. Maybe dig into the Liquid documentation to see what’s possible.

---

<div class="post-metadata">

**Author:** ![jpc](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/jpc/32/2643_2.png) [@jpc](https://talk.jekyllrb.com/u/jpc)\
**Post date:** [September 23, 2020, 2:39pm UTC](https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951/9 "2020-09-23T14:39:17Z")

</div>

What about that ?

> **[Jekyll Post Navigation Within a Category | Adam James Clarkson](https://ajclarkson.co.uk/blog/jekyll-category-post-navigation/)**

I suppose you already tested it !

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [September 23, 2020, 3:44pm UTC](https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951/10 "2020-09-23T15:44:36Z")

</div>

More importantly, have you tested it?

I’ve used a variant of this back when my personal site was built with Jekyll. It worked fine. Don’t know what your setup is, but if you’re hosting directly with GitHub Pages and not using GitHub actions to build you won’t be able to use this method, as it’s a custom Jekyll/Ruby plugin.

---

<div class="post-metadata">

**Author:** ![jpc](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/jpc/32/2643_2.png) [@jpc](https://talk.jekyllrb.com/u/jpc)\
**Post date:** [September 23, 2020, 3:49pm UTC](https://talk.jekyllrb.com/t/gallery-according-taxonomy-next-previous-buttons/4951/11 "2020-09-23T15:49:32Z")

</div>

No, I didn’t test it and I had forgotten the “problem” of the plugins !
