I am using Timber, and currently trying to get pagination working as per the Timber docs, though so far, without success. Below is my custom archive php file:
global $paged;
if (!isset($paged) || !$paged){
$paged = 1;
}
$context = Timber::get_context();
$args = array(
'post_type' => 'product',
'posts_per_page' => 2,
'paged' => $paged,
);
$context['subCatItems'] = new Timber\PostQuery($args);
Timber::render('archive-product.twig', $context);
And my corresponding Twig file:
<div class="l-container vert-push--small vert-push--adult--medium">
{% for post in posts %}
<div class="c-std">{{ post.title }}</div>
{% endfor %}
</div>
<div class="tool-pagination c-std">
{% if posts.pagination.prev %}
<a href="{{posts.pagination.prev.link}}" class="prev {{posts.pagination.prev.link|length ? '' : 'invisible'}}">Prev</a>
{% endif %}
<ul class="pages">
{% for page in posts.pagination.pages %}
<li>
{% if page.link %}
<a href="{{page.link}}" class="{{page.class}}">{{page.title}}</a>
{% else %}
<span class="{{page.class}}">{{page.title}}</span>
{% endif %}
</li>
{% endfor %}
</ul>
{% if posts.pagination.next %}
<a href="{{posts.pagination.next.link}}" class="next {{posts.pagination.next.link|length ? '' : 'invisible'}}">Next</a>
{% endif %}
</div>
The main issue at the moment is that posts_per_page
seems to do nothing, and I am just getting all the posts rendering on the page (about 20 currently), when there should be only 2 with the pagination (which isn't currently showing. Any ideas?