Wordpress 显示孙辈的父代

Wordpress 显示孙辈的父代,wordpress,Wordpress,我有个小问题 我有一个父母,一个孩子,一个孙子,一个大孙子和一个大孙子作为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=&

我有个小问题

我有一个父母,一个孩子,一个孙子,一个大孙子和一个大孙子作为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');
函数wpb_list_child_pages_popup(){
全球$员额;
如果(是页面()&&$post->post\U父项)
$childpages=wp\u list\u pages('sort\u column=menu\u order&title\u li=&child\u of='。$post->post\u parent.&echo=0');
其他的
$childpages=wp_list_pages('sort_column=menu_order&title_li=&child_of='。$post->ID.&echo=0');
如果($childpages){
$string='
    。$childpages.
'; } 返回$string; } 添加快捷代码(“wpb子页面弹出”、“wpb子页面列表弹出”);
我只看到当前子页面或大孙子页面的父页面

如何及时使用此代码以确保取消当前页面在列表中显示两位家长?


<?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 } ?>
试试这个

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');
函数wpb_list_child_pages_popup(){
全球$员额;
$thispage=$post->ID;
$pagekids=get_pages(“child_of=”.$thispage.&sort_column=menu_order”);
if($pagekids){//pagekids中是否存储了任何值,因此当前页面具有子页面
回声“
    ”; wp_list_pages(“depth=1&title_li=&sort_column=menu_order&child_of=“.$thispage);//仅显示当前页面的子页面 回声“
”; }elseif($post->post\U父项){ $children=wp_列表_页面(“title_li=&children_of=“.$post->post_parent.”&echo=0”); } if($children){//如果当前页没有子页 回声“
    ”; 儿童; 回声“
”; } } 添加快捷代码(“wpb子页面弹出”、“wpb子页面列表弹出”);
谢谢,但问题是我在模板中使用了一个短代码。如何合并这两个代码,使其通过短代码工作?