As @mmistakes suggested me I created a gallery according the category.
I created a my_gallery.md page and added in the yaml:
my_gallery display all posts with the foo category.
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 ?
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.
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 ?
_layout/single.html has an include for post pagination, the (next/previous) links. That code is here:
This uses Jekyll’s
page.next variables, which coming from the Jekyll docs 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.
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
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.
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 ?
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.
What about that ?
I suppose you already tested it !
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.
No, I didn’t test it and I had forgotten the “problem” of the plugins !