### [WordPress 父页面中显示子页面列表](https://www.prosaas.cn/article/9709) **Published:** 2019-10-22T03:31:25 **Author:** 5201314 **Excerpt:** 如果想在WordPress 父页面中显示子页面列表链接,可以通过下面的代码实现,下面由WordPress教程栏… 如果想在WordPress 父页面中显示子页面列表链接,可以通过下面的代码实现,下面由**WordPress教程**栏目给大家介绍。 ![](//zhiqipro.oss-cn-beijing.aliyuncs.com/2023/12/20231212132651897.jpg) WordPress 父页面中显示子页面列表将下面的代码添加到当前主题 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 = ''; } return $string; } add\_shortcode('wpb\_childpages', 'wpb\_list\_child\_pages'); 之后,可以使用短代码: \[wpb\_childpages\] 加到文本小工具中。 默认文本小工具不支持短代码,可以将: add\_filter('widget\_text', 'do\_shortcode'); 添加到当前主题 functions.php 中,让文本小工具支持短代码。 也可以将下面的代码添加到主题页面模板适当的位置: 比如新建一个页面模板,将代码加进去,只在使用该功能时,选择新建的页面模板。 以上就是WordPress 父页面中显示子页面列表的详细内容,更多请关注知企PROSAAS其它相关文章! **Tags:** php, WordPress **Categories:** WordPress ---