国内外主机
测评及优惠码

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 中,让文本小工具支持短代码。

也可以将下面的代码添加到主题页面模板适当的位置:

比如新建一个页面模板,将代码加进去,只在使用该功能时,选择新建的页面模板。

以上就是WordPress 父页面中显示子页面列表的详细内容,

赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《WordPress 父页面中显示子页面列表是怎么操作的》
文章链接:https://www.ibytx.com/2919.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

登录

找回密码

注册