2012-01-11 21 views
0

我目前有一個腳本,輸出基於站點菜單的輔助導航,但我不能想到反正鏈接到一個頁面的帖子,以便職位仍然可以顯示輔助導航,這甚至有可能嗎?以下是我用於輸出輔助導航的當前代碼: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>'; 
?> 
+0

您的最終結果尚不清楚。提供關於次級導航何時/如何出現的更多解釋。 – 2012-01-11 15:37:31

+0

它目前輸出您正在瀏覽的頁面以及與當前頁面有關係的任何子項,問題是我不確定如何創建頁面和帖子之間的關係 – Nick 2012-01-12 08:35:27

回答

1

頁面是斜體的,所以他們可以有父母和孩子。 帖子是平的,並通過類別和標籤相關。

爲了將帖子與頁面相關聯,我認爲您需要在帖子上使用自定義字段。您可以將其稱爲父頁面ID,然後在側邊欄代碼中添加一個自定義查詢,以檢查其父頁ID =當前頁面ID的帖子。

+0

謝謝,這是一個好主意! – Nick 2012-01-13 11:09:06

0

檢出Flexi Pages Widget。這將爲您的側邊欄添加高度可配置的子頁面菜單,您可以在帖子&頁面上嵌入該菜單。

+0

謝謝,但它似乎不允許你輸出在菜單中的帖子,只有頁面,這是我已經有的代碼 – Nick 2012-01-12 08:54:25