Skip to content

Instantly share code, notes, and snippets.

@jcasabona
Last active December 8, 2019 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcasabona/c02cc6bf955af5d177b226664916d1b2 to your computer and use it in GitHub Desktop.
Save jcasabona/c02cc6bf955af5d177b226664916d1b2 to your computer and use it in GitHub Desktop.
Paginate Child Pages
function paginate_child_pages( $post ) {
$page_id = $post->ID;
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $page_id,
'order' => 'ASC', //change to fit your order
'orderby' => 'menu_order', //change to fit your order
);
$child_pages = new WP_Query( $args );
if ( $child_pages->have_posts() ) {
$pagination = '<ul class="pages">\n';
$format = '\t<li><a href="%1$s">%2$s</a></li>\n';
$counter = 0;
while ( $parent->have_posts() ) {
$parent->the_post();
$counter++;
$pagintation .= sprintf( $format, get_the_permalink(), $counter );
}
$pagination .= '</ul>';
}
wp_reset_postdata();
return $pagination;
}
@jcasabona
Copy link
Author

Caveats:

  • This is quick, dirty, and untested.
  • You probably don't need to pass $post. You can make the first line of the function global $post;
  • You'll almost definitely run into string literal issues with the \t and \n within single quotes.
  • This returns a string that can then be printed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment