Get the App
SLTechnology News&Howtos  ›  Servers  › 

How WordPress displays a list of child pages in the parent page

Shulou Source: shulou.com Published: 2022-06-02 01:20:57 09月15日 Update

How does WordPress display a list of child pages in the parent page? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!

Display a list of child pages in the WordPress parent page to 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 =''. $childpages. '';} return $string;} add_shortcode ('wpb_childpages',' wpb_list_child_pages')

After that, you can use short code:

[wpb_childpages]

Add to the text gadget.

The default text gadget does not support short codes, and you can set:

Add_filter ('widget_text',' do_shortcode')

Add to the current theme functions.php to make the text gadget support short code.

You can also add the following code to the appropriate location of the theme page template:

For example, create a new page template, add the code, and select the new page template only when using this feature.

Thank you for reading! After reading the above, do you have a general idea of how WordPress displays a list of child pages in the parent page? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.

Tags: Pages code content themes tools text templates articles questions face-to-face support appropriate location functions more watch industry information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Information Linux MySQL Apple