【发布时间】:2012-01-11 15:30:39
【问题描述】:
我目前有一个脚本可以输出基于站点菜单的辅助导航,但是无论如何我都无法将帖子链接到页面以便帖子仍然可以显示辅助导航,这甚至可能吗?这是我用来输出辅助导航的当前代码:
<?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>';
?>
【问题讨论】:
-
您的最终结果尚不清楚。提供有关辅助导航何时/如何出现的更多说明。
-
它当前输出您所在的页面以及与当前页面有关系的任何孩子,问题是我不确定如何在页面和帖子之间创建关系
标签: php wordpress navigation