2017-07-10 71 views
0

如何让一个页面的孩子们的大孩子?如何让孩子们和他们的大孩子

<?php 
global $post; 
$pages = get_children(array(
    'post_parent' => $post->ID, 
    'numberposts' => -1 
)); 

if ($pages): 
    $rows = array_chunk($pages, ceil(count($pages)/3)); ?> 
    <div class="row"> 
     <?php foreach ($rows as $row): ?> 
      <div class="col-sm-4"> 
       <ul class="list-unstyled"> 
        <?php foreach ($row as $city): ?> 
         <li><a href="<?= get_permalink($city) ?>"><?= $city->post_title ?></a></li> 
        <?php endforeach; ?> 
       </ul> 
      </div> 
     <?php endforeach; ?> 
    </div> 
<?php endif; 

使用wp_list_pages我不能为我的名单

+0

检查了这一点https://wordpress.stackexchange.com/questions/247858/wp-list-pages-change-output-of-hyperlink – Noman

回答

0

做出的列显示双方父母和孩子的页面孩子的页面链接。

<?php 
    global $post; 
    // Use parent page if exists, else use current page  
    $child_of_value = ($post->post_parent ? $post->post_parent : $post->ID); 
    // Depth of 2 if parent page, else depth of 1 
    $depth_value = ($post->post_parent ? 2 : 1); 
    // Build argument array 
    $wp_list_pages_args = array( 
     'child_of' => $child_of_value, 
     'depth' => $depth_value, 
     'title_li' => 'Sections', 
     'echo' => 0 
    ); 
    // Now, output the result 
    wp_list_pages($wp_list_pages_args); 

?> 
+0

但如何在主页儿童添加和grandchildrens页面? –

+0

使用$ post-> ID获取您的主页ID并传入$ post-> post_parent:$ post-> ID –