Jekyll Pagination for multiple pages - pagination

So right now I have the following in my config.yml:
gems: [jekyll-paginate]
paginate: 3
paginate_path: "page:num"
So in my index.html page I have the following:
{% for post in paginator.posts %}
Stuff
{% endfor %}
I am having trouble figuring out how I would make separate category pages and have pagination for them.
Could anyone help me shed light? I've been googling forever and I haven't been able to find anything.

Jekyll only manages posts pagination.
If you want to paginate categories, you will need a plugin like https://github.com/midnightSuyama/jekyll-paginate-category.

Related

Pagination works for archive of CPT but throws 404 error for single-cpt.php

I can use Timber pagination in archive-law.php for the archive page (/law/page/2) of my custom post type, "law", but with the same codes in single-law.php, the second page (/law/cpt-post-slug/page/2) shows the 404 error. How can I fix that?
That’s how it’s supposed to work. Pagination only works for archive templates like archive.php or home.php, where you have a query with multiple results that can be paginated. It will not work for singular templates like single.php.
However, you could use next_post_link() and previous_post_link(), which display a link to the next or previous post which exists in chronological order from the current post.
In Timber, these functions are available as post.next and post.prev. Here’s an example for how you could use it in in a singular template in Twig:
{% if post.next %}
<h3>Next Article</h3>
{{ post.next.title }}
{% endif %}

Grav CMS: how to show/hide parts of the page depending on conditions?

The Grav's documentation clearly describes how a whole page or a folder could be hidden from unregistered users. It also describes how a whole page could be seen only by particular user groups.
But what about pieces of a page, let's say, some links or a private info I want to show on some conditions?
Ok, for registered users I found a snippet at Login plugin docs:
{% if grav.user.authenticated %}
content for registered users goes here
{% endif %}
But going wider - how can I show/hide pieces of a particular page depending on some custom logic in PHP code, i.e. not necessarily user related?
I'm thinking about a twig/shortcode plugin, something like:
{% if some.custom.condition.or.PHP.function %}
hidden content goes here
{% endif %}
or
[hidden_if_something] hidden content goes here [/hidden_if_something]
But not sure how exactly this should be implemented. So working examples would be appreciated. Thanks.
There is a recipe in the Grav documentation here. This provides an example of how to render the output of a PHP code result in a twig template.
In the example they create a plugin, and implement a twig extension providing access to a php function. They can then simply call that php function like in a twig template.
{{ example() }}
Following that example, you can implement whatever logic you would like in php, and call the function in a twig if statement.
{% if example() == true %}
your conditional output
{% endif %

what exactly is haswidgets and widgets in bolt (or twig rather )?

I was just going through the Default theme of bolt CMS, and i came actoss the following lines of code:
{% if haswidgets('aside_top') %}
{{ widgets('aside_top') }}
{% else %}
I googled twig haswidgets and also twig widgets , but i could't find anything.
can somebody explain what these two methods are ? and what exactly do they do ?
They are a feature of Bolt. Extensions can push content to specific places in the backend and also to some places in the frontend, as long as the theme supports that. They are called widgets. the haswidgets() and widgets() twig functions are for checking and displaying them.
You can find more info here https://docs.bolt.cm/3.1/templating/widgets and here https://docs.bolt.cm/3.1/extensions/intermediate/widgets

Paginate Shopify blog with offset? (Liquid)

I'm trying to figure out how to paginate a blog starting at a specific offset. For example, the first page features posts 5-8, the second page 9-12, third page 13-16, and so on. This doesn't seem to work, but I'm looking for something along these lines -
{% paginate blog.articles offset:4 by 4 %}
{% for article in blog.articles
...
{% endfor %}
{% endpaginate %}
Are there any workarounds here?
I was trying to see if there's any way I could find a decent workaround in Liquid but there isn't, since you're offsetting a full page; it'd be perfectly possible to show 5-8 on the first page, but you'd need to show 9-16 on second page and so on and so forth. I'm afraid Shopify paginate won't help you here.
There could be specific workarounds for your situation; please give us more detail and we'll see. For example, if you always want to show the four latest blog articles on every page, and leave pagination handle the rest, a possible way would be to do something as per the following:
{% for article in blogs.news.articles limit: 4 %}
{{ article.title }}
{% endfor %}
{% paginate blog.articles by 4 %}
{% unless paginate.current_page == 1 %}
{% for article in blog.articles %}
{{ article.title }}
{% endfor %}
{% endunless %}
{% include 'pagination' %}
{% endpaginate %}
So outside of any pagination go through the handle to obtain the latest 4 to feature them, and if you're not on page 1, use pagination to print 4 more articles on each page.
If not, this is one of the scenarios where you should consider exposing your own service that internally calls and retrieves articles from the Shopify API as per your needs.
The offset should be specified in your loop parameters, not in pagination.

Custom order for a loop in Grav CMS (uses Twig)

I'm listing all the pages (from different folders) belonging to category "featured", and I'd like to order them by a custom value. At the moment they're being ordered by date:
{% for p in taxonomy.findTaxonomy({'category':'featured'}).order('date','desc') %}
{{ p.title }}
{% endfor %}
However I want to add an "order" field in the page header
---
// for the first page to show
title: Just a page
order: 1
---
// for the second page to show
title: Not just a page
order: 2
---
What I want is something like .order('p.header.order','asc')
Is there any way to do this?
I got help from #rhukster at Grav forums but posting the solution here as well. It's simple.
.order('header.order','asc')
grav has the option to order folders by adding a number at the beginning of the folder name.

Resources