2012-08-28 40 views
1

孩子和孫子頁面內容我在WordPress的頁面結構是這樣的:顯示在WordPress的

  • 主頁
    • 首頁孩子
      • 首頁孫子
      • 主頁孫子
      • 主頁孫子
      • 主頁孫子
    • 首頁孩子
      • 首頁孫子
      • 首頁孫子
      • 首頁孫子
      • 首頁孫子

等..

我只想爲自己的主頁上的每個子頁面/孫子頁面顯示標題/內容,請任何人都可以幫忙?

回答

0

您應該使用wp_list_pages()函數,並指定頂級祖先和級別2

<?php 

    $postid = get_the_ID(); 
    $topid = get_top_ancestor($postid); 

    $args = array(
      'depth'  => 2, 
      'show_date' => '', 
      'date_format' => get_option('date_format'), 
      'child_of'  => $topid, 
      'exclude'  => '', 
      'include'  => '', 
      'title_li'  => '', 
      'echo'   => 1, 
      'authors'  => '', 
      'sort_order' => 'ASC', 
      'link_before' => '', 
      'link_after' => '', 
      'walker'  => '', 
      'post_type' => 'page', 
      'post_status' => 'publish' 
); ?> 
<ul> 
    <?php wp_list_pages($args); ?> 
</ul> 
+0

謝謝你,但我想顯示這些子頁面和孫子頁面的內容和標題,而不是列出頁面。請有任何想法嗎? – aboother