Using the example detailed here in the documentation on pagination, I'm running into a 404 issue when using the pagination links. So going to any page but the first page 404s.
The custom post type that I'm working with is in_the_news of which I need 9 on each page. Below is the code that I'm using:
<?php
/**
* Template Name: In The News
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/
global $paged;
if (!isset($paged) || !$paged){
$paged = 1;
}
$context = Timber::get_context();
$args = array(
'post_type' => 'in_the_news',
'posts_per_page' => 9,
'paged' => $paged
);
/* THIS LINE IS CRUCIAL */
/* in order for WordPress to know what to paginate */
/* your args have to be the defualt query */
query_posts($args);
/* make sure you've got query_posts in your .php file */
$context['posts'] = Timber::get_posts();
$context['pagination'] = Timber::get_pagination();
Timber::render('in-the-news.twig', $context);
The only things that I've changed from the example is the post_type, posts_per_page, & the twig file to render everything to.
I've search through the issues, open & closed, trying a number of things. But I'm at a wits end, as I'm really just a front-end dev building out a CMS. This is pretty much the only issue I have left to fix as I've got to launch the site tomorrow so help would be very much appreciated.
Thanks in advance.
Well I figured it out by pure chance of falling on the Routes documentation.
Had to create a custom route for the custom post type. Might want to mention that in the pagination documentation.
Added the following code to functions.php
Timber::add_route('in-the-news/page/:pg', function($params){
$query = 'posts_per_page=9&post_type=in_the_news&paged='.$params['pg'];
Timber::load_template('in-the-news.php', $query);
});
Most helpful comment
Well I figured it out by pure chance of falling on the Routes documentation.
Had to create a custom route for the custom post type. Might want to mention that in the pagination documentation.
Added the following code to functions.php