If you want to display the sub-page list link in the WordPress parent page, you can achieve it through the following code. The following is introduced by the WordPress Tutorial column.
To display a list of child pages in the WordPress parent page, add the following code to the current theme functions.php:
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('wpb_childpages', 'wpb_list_child_pages');
After that, you can use the shortcode:
[wpb_childpages]
Add to text widget.
The default text widget does not support short codes. You can add:
add_filter('widget_text', 'do_shortcode');
to the current theme functions.php to make the text widget support short codes.
You can also add the following code to the appropriate location of the theme page template:
<?php wpb_list_child_pages(); ?>
For example, create a new page template, add the code, and only select the newly created page when using this function template.
The above is the detailed content of Display child page list in WordPress parent page. For more information, please follow other related articles on the PHP Chinese website!