如果想在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 = '<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 父页面中显示子页面列表的详细内容,更多请关注知企PROSAAS其它相关文章!
文章链接:https://www.prosaas.cn/9709.html
更新时间:2019年10月22日
声明: 本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:973664285@qq.com我们将第一时间处理! 资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。 所有资源仅限于参考和学习,版权归原作者所有,更多请阅读知企PROSAAS协议