2011-05-18 117 views
0

我想在wordpress站點上的所有頁面的頁腳中顯示孩子頁面的地毯。如何在所有頁面上顯示一位家長的子頁面wordpress

在我使用的頁腳代碼

  <?php 
     global $wp_query; 
     $post = $wp_query->post; 
     $ancestors = get_post_ancestors($post); 
     if(empty($post->post_parent)) { 
      $parent = $post->ID; 
     } else { 
      $parent = end($ancestors); 
     } 
     if(wp_list_pages("title_li=&child_of=$parent&echo=0")) { ?> 

     <ul class="footerNav clearfix"> 
      <?php wp_list_pages("title_li=&child_of=$parent&depth=1"); ?> 
     </ul><!-- #secondary-nav --> 

     <?php } ?> 

然而,這隻能說明,當你在相關產品類別頁腳中的子頁面,我想看到的所有網頁上這個導航。

感謝,

週六

這裏是鏈接到一個頁面頁腳如何,我想它

http://satbulsara.com/luke-irwin/rugs/new-in/fishy/

回答

1

所有頁面使用

$post = $wp_query->post; 
$ancestors = get_post_ancestors($post); 

變量$ post分配了訪問者當前正在查看的帖子。

如果你想要所有頁面上的地毯的所有孩子的菜單,你只需要你的代碼的底部。此外,child_of參數不需要被通過可變分配,可以輸入的地毯靜態頁面ID,即:

<ul class="footerNav clearfix"> 
    <?php wp_list_pages("title_li=&child_of=173&depth=1&sort_column=post_name"); ?> 
</ul><!-- #secondary-nav --> 

這三行將在生成菜單你就足夠了。如果聲明你周圍有檢查特定的父頁面是否有孩子,只有生成一個無序列表,如果是的話。既然你知道它存在於這種情況下,我會放棄它並保存這兩行。爲了完整起見,我已經包含了sort_column參數 - 這將爲您提供按字母順序排列的所有地毯菜單。

如果聲明僅適用於根據訪問者當前所在頁面而改變的動態菜單。如果你想要實現這樣的菜單,我仍然會以不同的方式去思考,並且認爲上述過程是臃腫的。只需插入

<?php $ancestors = get_post_ancestors($post); ?> 

到您的header.php文件將讓你與

<?php if (is_page(173) || in_array(173,$ancestors)) { ?> 
    <ul class="subnav"> 
     <?php wp_list_pages('title_li=&child_of=173&depth=1'); ?> 
    </ul> 
<?php } ?> 

其他地方一樣產生動態菜單上面所說的,爲您的特定情況下,拳頭代碼塊三班輪足夠。

另外參考:WP Codex: wp_list_pages

+0

喜我改成了$祖先= $祖先= get_post_ancestors(175); – sat 2011-05-19 11:44:32

+0

仍然得到相同的東西 – sat 2011-05-19 11:45:39

+0

我做了一個累了的思維錯誤。我昨天給你的代碼抓住了'_rugs_'的祖先 - 即你的主頁(slug'_luke-irwin_')。然而,因爲你已經想出了將其改變爲175它會起作用,如果你刪除了整個'$ wp-query'的東西和_if_語句,只留下'$ ancestors = get_post_ancestors(175);'和'$ parent = end($ ancestors);' 無論如何,我已經更新了我的答案。 – 2011-05-19 20:44:06

相關問題