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 = '<ul>' . $childpages . '</ul>'; } return $string; } add_shortcode('wpb_childpages', 'wpb_list_child_pages');
以后,能够运用短代码:
[wpb_childpages]
加到文本小工具中。
默许文本小工具不支撑短代码,能够将:
add_filter('widget_text', 'do_shortcode');
添加到当前主题 functions.php 中,让文本小工具支撑短代码。
也能够将下面的代码添加到主题页面模板恰当的位置:
<?php wpb_list_child_pages(); ?>
比方新建一个页面模板,将代码加进去,只在运用该功用时,挑选新建的页面模板。
以上就是WordPress 父页面中显现子页面列表的细致内容,更多请关注ki4网别的相干文章!