Skip to content

Instantly share code, notes, and snippets.

@beovulf
Created February 5, 2016 13:16
Show Gist options
  • Save beovulf/dd61398e0b2fe18c911f to your computer and use it in GitHub Desktop.
Save beovulf/dd61398e0b2fe18c911f to your computer and use it in GitHub Desktop.
Pagination on pages
<?php
$q = new WP_Query( array( 'post_type' => 'page', 'post_parent' => $page_ID, 'depth' => 1, 'posts_per_page' => 4, 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1) ) );
if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
?>
<?php endwhile;
if ( get_option('permalink_structure') ) {
$format = 'page/%#%';
} else {
$format = '&paged=%#%';
}
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args2 = array(
'base' => get_permalink( $post->post_parent ) . '%_%',
'format' => $format,
'current' => $paged,
'total' => $q->max_num_pages
); ?>
</div>
<div class="row"><div class="col-xs-12 pagination">
<?php echo paginate_links( $args2 ); ?>
</div></div>
<?php wp_reset_query(); endif ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment