I have an events page which I would like to add pagination to. However, with it being a custom post type I am finding it rather difficult. I have managed to get pagination working for my news page, but I cannot get the same result for the events page. Here is my code for the events page
<?php
get_header();
get_sidebar('left');
?>
<article class="content-main events" role="main" id="post-<?php the_ID() ?>">
<?php include 'breadcrumbs.php'; ?>
<?php query_posts(array('posts_per_page'=>'2')); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="news-post">
<h1><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h1>
<?php the_excerpt() ?>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<!--Pagination-->
<?php echo paginate_links( $args ) ?>
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>
</article><!-- //.content-main -->
<?php
get_footer();
If I try to change this
<?php query_posts(array('posts_per_page'=>'2')); ?>
to this
<?php query_posts(array('category_name'=>'events','posts_per_page'=>'2')); ?>
This doesnt work either. However, if I remove the line altogether, it shows up the news post types. I am stumped!
just replace below function in functions.php file note: in backend setting->reading->post per page : set this value to one
you need to add global $paged and then in your array that is being passed to WP_Query you need to add 'paged' => $paged
">Pagination for custom post types should work the same as normal posts.
If you take a look at the default theme TwentyEleven you can see how they do it.
Basically they use next_posts_link() and previous_posts_link() functions.
You can look at that in functions.php > twentytwelve_content_nav();
Cheers,