WordPress 父页面中显示子页面列表-WordPress

资源魔 45 0

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 父页面中显示子页面列表的具体内容,更多请存眷资源魔其它相干文章!

标签: WordPress wordpress教程 wordpress自学 wordpress技术

抱歉,评论功能暂时关闭!