wordpress開發主題時,會遇到父頁面調用子頁面標題的時候,比如,在開發一個wordpress企業主題時,企業的服務項目,有并列的時候,這個時候就需要,把具體的服務項目,放到服務項目分類下。比如,培訓服務,具體的服務項目是,英語培訓、語言培訓、奧數培訓等。
這里需要把服務項目作為父頁面,具體服務項目做為子頁面。在服務項目父頁面通過以下代碼,調用出子頁面的標題,具體代碼如下:
<?php
if($post->post_parent)
$children = wp_list_pages("sort_column=menu_order&title_li=&child_of=".$post->post_parent."&echo=0&depth=1");
else
$children = wp_list_pages("sort_column=menu_order&title_li=&child_of=".$post->ID."&echo=0&depth=1");
if ($children) {
echo '<ul class="service-list">';
echo $children;
echo '</ul>';
} ?>