Home > CMS Tutorial > WordPress > body text

Display child page list in WordPress parent page

藏色散人
Release: 2019-10-22 11:31:25
forward
2677 people have browsed it

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.

Display child page list in WordPress parent page

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 = &#39;<ul>&#39; . $childpages . &#39;</ul>&#39;;
}
return $string;
}
add_shortcode(&#39;wpb_childpages&#39;, &#39;wpb_list_child_pages&#39;);
Copy after login

After that, you can use the shortcode:

[wpb_childpages]
Copy after login

Add to text widget.

The default text widget does not support short codes. You can add:

add_filter(&#39;widget_text&#39;, &#39;do_shortcode&#39;);
Copy after login

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(); ?>
Copy after login

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!

Related labels:
source:zmingcx.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!