我有点问题。
我有一个父母,一个孩子,一个大孩子,一个大孩子和一个伟大的大孩子作为wordpress中的页面结构。
我使用的代码是:
function wpb_list_child_pages_popup() {
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 id="child-menu">' . $childpages . '</ul>';
}
return $string;
}
add_shortcode('wpb_childpages_popup', 'wpb_list_child_pages_popup');
我只看到当前子页面或伟大的子页面的父级。
如何按时使用此代码以确保当前页面在列表中显示2个父母?
答案 0 :(得分:0)
<?php global $post; $thispage = $post->ID; // grabs the current post id from global and then assigns it to thispage ?>
<?php $pagekids = get_pages("child_of=".$thispage."&sort_column=menu_order"); // gets a list of page that are sub pages of the current page and assigns then to pagekids ?>
<?php if ($pagekids) { // if there are any values stored in pagekids and therefore the current page has subpages ?>
<ul>
<?php wp_list_pages("depth=1&title_li=&sort_column=menu_order&child_of=".$thispage); // display the sub pages of the current page only ?>
</ul>
<?php } elseif($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); if ($children) { // if there are no sub pages for the current page ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
答案 1 :(得分:0)
试试这个
function wpb_list_child_pages_popup() {
global $post;
$thispage = $post->ID;
$pagekids = get_pages("child_of=".$thispage."&sort_column=menu_order");
if ($pagekids) { // if there are any values stored in pagekids and therefore the current page has subpages
echo '<ul>';
wp_list_pages("depth=1&title_li=&sort_column=menu_order&child_of=".$thispage); // display the sub pages of the current page only
echo '</ul>';
} elseif($post->post_parent){
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
}
if ($children) { // if there are no sub pages for the current page
echo '<ul>';
echo $children;
echo '</ul>';
}
}
add_shortcode('wpb_childpages_popup', 'wpb_list_child_pages_popup');