2011-10-18 2 views
1

프로젝트에 대해 wordpress를 사용하고 있으며 wp_list_pages 함수에서만 요청하는 페이지를 탐색하기 위해 애쓰는 데 어려움을 겪고 있습니다. 메인 mav, 그 페이지에 자녀가있는 경우 드롭 다운에 표시합니다. 아래 코드는 현재 사용중인 코드입니다.wp_list_pages는 페이지를 포함하고 어린이를 드롭 다운으로 표시합니다.

<?php wp_list_pages('title_li=&sort_column=post_date&include=138,110,135,101,167'); ?>

어떻게 포함 된 페이지의 자식을 표시합니까?

답변

1

이 상황에서 가장 잘 맞는 것은 wp_list 페이지 사용을 잊어 버리는 것입니다. 대신 쿼리를 만든 다음 결과를 반복하여 페이지 하위 항목을 가져옵니다.

예 :

<ul> 
<?php 
    $args = array(
     'include' => array(138, 110, 135, 101, 167), 
     'orderby' => 'post_date', 
     'post_type'=> 'page', 
    ); 

    /* Get posts according to arguments defined above */ 
    $pages = get_posts($args); 

    echo "<ul>"; 

    /* Loop through the array returned by get_posts() */ 
    foreach ($pages as $page) { 

     /* Grab the page id */ 
     $pageId = $page->ID; 

     /* Get page title */ 
     $title = $page->post_title; 
     echo "<li>$title</li>";   

     /* Use page id to list child pages */ 
     wp_list_pages("title_li=&child_of=$pageId"); 

     /* Hint: get_posts() returns a lot more that just title and page id. Uncomment following 3 lines to see what else is returned: */ 
     //echo "<pre>"; 
     //print_r($page); 
     //echo "</pre>"; 
    } 
    echo "</ul>"; 
?> 
</ul> 

그리고 당신의 출력과 같이 보일 것입니다 :

<ul> 
    <li>Parent Page1<li> 

    <ul> 
     <li>Child page1</li> 
     <li>Child page2</li> 
     <li>Child page etc</li> 
    </ul> 

    <li>Parent Page2</li> 

    <ul> 
     <li>Child page1</li> 
     <li>Child page2</li> 
     <li>Child page etc</li> 
    </ul> 

    ...and so forth 
</ul> 
관련 문제