Rumah  >  Artikel  >  Tutorial CMS  >  WordPress 父页面中显示子页面列表

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

藏色散人
藏色散人ke hadapan
2019-10-22 11:31:252630semak imbas

如果想在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 = &#39;<ul>&#39; . $childpages . &#39;</ul>&#39;;
}
return $string;
}
add_shortcode(&#39;wpb_childpages&#39;, &#39;wpb_list_child_pages&#39;);

之后,可以使用短代码:

[wpb_childpages]

加到文本小工具中。

默认文本小工具不支持短代码,可以将:

add_filter(&#39;widget_text&#39;, &#39;do_shortcode&#39;);

添加到当前主题 functions.php 中,让文本小工具支持短代码。

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

<?php wpb_list_child_pages(); ?>

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

Atas ialah kandungan terperinci WordPress 父页面中显示子页面列表. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Artikel ini dikembalikan pada:zmingcx.com. Jika ada pelanggaran, sila hubungi admin@php.cn Padam