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

如果想在wordpress页面显示页面列表链接,可以通过下面代码实现,下面由Wordpress教程栏目给大家介绍。

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 = '
登录后复制
    ' . $childpages . '
'; } 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 父页面中显示子页面列表的详细内容,更多请关注慧达AI工具网其它相关文章

转载请说明出处 内容投诉内容投诉
慧达seo-站长工具-seo工具-采集-发布-AI文章生成发布工具 » WordPress 父页面中显示子页面列表

慧达AI专注站群seo管理工具

查看演示 官网购买