I currently have a script that outputs a secondary navigation based on the site menus, however I can’t think of anyway to link a post to a page so that the posts can still show a secondary navigation, is this even possible? Here is the current code i’m using to output my secondary navigation:
<?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>';
?>
Pages are heirarchical, so they can have parents and children.
Posts are flat, and related by categories and tags.
In order to relate a post to a page, I think you’re going to need to use a custom field on your posts. You could call it Parent Page ID, and then in your sidebar code, add a custom query that checks for posts whose Parent Page ID = the current page’s id.