2016-03-02 2 views
0

У меня есть небольшая проблема.Показать родителя grandchilderen

У меня есть один родитель, 1 ребенок, 1 великий ребенок, 1 великий ребенок и 1 великий великий ребенок, как структура страницы в 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
<?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 } ?> 
+0

Спасибо, но дело в том, я использую шорткод в своих шаблонах. как я могу объединить эти 2, чтобы заставить его работать через короткий код? – Dionoh

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'); 
Смежные вопросы