I want to use Pagination throughout a new theme but am having trouble getting it to work correctly.
I am using some code within my functions.php file and then calling that function. It works on the ‘blog’ page but not on paginated posts or pages.
Here is my code:
// Pagination for paged posts, Page 1, Page 2, Page 3, with Next and Previous Links, No plugin
function canvas_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'type' => 'list'
));
}
add_action('init', 'canvas_pagination'); // Add our Pagination
And call the funtion: <?php get_template_part('pagination'); ?>
This code works great within the index.php file.
See here: http://website-test-lab.com/sites/blank_canvas/blog/
But not within single.php and page.php:
- SITE URL + /paginated/
- SITE URL + /page-pagination/
(Can’t add more than 2x links here)
Can someone explain why this doesn’t work and what needs to be amended to fix it.
I have tried using wp_link_pages but it’s not giving me the ability to customise the output I require.
Thanks in advance
Post Navigation
Here’s the way its done in the Twenty Twelve themes single.php file however it looks like Twenty Fourteen has a better solution which works for pages as well.
You could hook this code in from your functions file using a theme specific hook or filtering the WordPress content hook.
There’s some good examples of using the content filter in your functions file here.
More http://codex.wordpress.org/Next_and_Previous_Links
Page Navigation
Here’s a tutorial i wrote which uses the code from Twenty Fourteen theme.
It creates a template tag you can use in a custom function with hook and conditional tags or directly in a template file.
Step:1 Make Function in function.php
Step : 2 call the pagination function require to use