我目前有一個腳本,輸出基於站點菜單的輔助導航,但我不能想到反正鏈接到一個頁面的帖子,以便職位仍然可以顯示輔助導航,這甚至有可能嗎?以下是我用於輸出輔助導航的當前代碼:WordPress的 - 輸出自動輔助導航上的帖子以及頁
<?php
$secondAncestor = count($post->ancestors) -1; //figure out what level of navigation we are on, subtract one because we don't want to consider the top-level
if($post->post_parent!=0) //if the page is not a top-level category
{
echo '<nav><h2 class="widgettitle">In this section:</h2><ul class="secondary-nav"><li class="sidebarlist">';
//the following lists children of second level ancestor of the current page.
wp_list_pages("title_li=&child_of=".$post->ancestors[$secondAncestor]."& sort_column=menu_order&echo=1");
echo '</li>';
}
else //if the page is a top-level category
{
//listing only the child pages of the current section
$children= wp_list_pages("title_li=&child_of=".$post->ID."& sort_column=menu_order&echo=0");
if($children) //this will stop it from displaying a section heading if there are no elements in the section (for example on the home page)
{
echo '<nav><h2 class="widgettitle">In this section:</h2><ul class="secondary-nav"><li>';
echo $children;
echo '</li>';
}
}
echo '</ul></nav>';
?>
您的最終結果尚不清楚。提供關於次級導航何時/如何出現的更多解釋。 – 2012-01-11 15:37:31
它目前輸出您正在瀏覽的頁面以及與當前頁面有關係的任何子項,問題是我不確定如何創建頁面和帖子之間的關係 – Nick 2012-01-12 08:35:27