Last active
December 17, 2018 11:49
-
-
Save vanbernaert/710939144018a44a9c25bb1f613b1dea to your computer and use it in GitHub Desktop.
WordPress: List subpages on a parent page through a shortcode
This file contains 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 wpb_list_child_pages() { | |
global $post; | |
if ( is_page() && $post->post_parent ) | |
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' ); | |
else | |
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' ); | |
if ( $childpages ) { | |
$string = '<ul>' . $childpages . '</ul>'; | |
} | |
return $string; | |
} | |
add_shortcode('page_show_childpages', 'wpb_list_child_pages'); | |
//# Instructions | |
// Put this in functions.php | |
// use shortcode [page_show_childpages] on page to list subpages | |
// if you need it automatically on every page, puts next code in the page template php file: | |
// <?php wpb_list_child_pages(); ?> | |
// source: http://www.wpbeginner.com/wp-tutorials/how-to-display-a-list-of-child-pages-for-a-parent-page-in-wordpress/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And if i want to order the pages by date?
What should i change?
Thanks!