Last active
December 8, 2019 21:34
-
-
Save jcasabona/c02cc6bf955af5d177b226664916d1b2 to your computer and use it in GitHub Desktop.
Paginate Child Pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Caveats:
$post
. You can make the first line of the functionglobal $post;
\t
and\n
within single quotes.