Frizzant
Frizzant

Reputation: 768

Timber Pagination: page.php / not showing up

In the Timber for Wordpress DOCs (link) they say

This will only work in a php file with an active query (like archive.php or home.php) (...)

By my understanding, what I have done, is an active query (?). I need the pagination on one of my page.php sites however.

I can not get the pagination to display.

page.php

$context['blogposts'] = new Timber\PostQuery(array(
    'numberposts'   => -1,
    'posts_per_page'=> 2,
    'post_type'     => 'post',
    'order'         => 'DESC',
    'paged'         => (get_query_var('paged')) ? get_query_var('paged') : 1,
));

page.twig

<div id="blogposts-container">
    {% for post in blogposts %}
      {% include ['tease-'~post.post_type~'.twig', 'tease.twig'] %}
    {% endfor %}
  </div>

  {% include 'partial/pagination.twig' with { pagination: blogposts.pagination({show_all: false, mid_size: 3, end_size: 2}) } %}

This pretty much exact logic works for the index + article pages (yes I tested it). How can I get it to work for a page/custom page?

Dumping blogposts.pagination gives me the correct list of items.

Upvotes: 1

Views: 703

Answers (1)

Frizzant
Frizzant

Reputation: 768

Turns out i should have shown the pagination.twig too. In my case I had to:

{% set posts = blogposts %}

for this partial to work. Due to the partial using posts as the base object for displaying content.

Upvotes: 1

Related Questions