Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following code showing up a sub-menu on my website (in my header.php file) that shows all well and good, however when I open up a post it dissapears:

<div id="dep-menu">
    <?php global $post;
    if (!is_front_page()) { // so I don't display a link on the homepage saying "Homepage"
        if($post->post_parent) { //if page has parent
            $children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0"); //include a link to the parent
            $children.= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); //add the child pages
        } else {
            $children = wp_list_pages("title_li=&include=".$post->ID."&echo=0");//parent link
            $children.= wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");//children
        }
        if ($children) { ?>
            <ul>
            <?php echo $children; ?>
            </ul>
        <?php }
    }
?>
</div>

This works all well and good for my pages. The pages on this site are effectively get x posts from y category and display title and excerpt. No page is more than 2 deep cat wise meaning no url is more than domain.com/cat-x/cat-y/ and the menu works on those pages.

When I open a post with the url scheme of domain.com/cat-x/post-title/ the menu drops off.

BEGIN EDIT

As there seemed to be some confusion, my page hierarchyis like so:

parent 1
    child 1-1
    child 1-2
parent 2
    child 2-1
    child 2-1

parent 1 corresponds to a category name and when clicked a submenu showing parent 1 | child 1-1 | child 2-1 shows up each displaying all the posts in their namesake categories.

However when I click on a post the submenu disappears, and I need it to stay persistent.

END EDIT

Essentially, how do I get the menu to display again? As far as I can tell it should stay there as it still fits the url schema and has the same category.

share|improve this question
    
Did you get all Contents wp_list_pages( $args ); –  ayyan Mar 6 '12 at 13:13

1 Answer 1

up vote 1 down vote accepted

your menu is pages oriented. pages have parents and the query asks for the parent and the siblings.

When accessing posts, posts have no hirarcy, wp_list_pages will not work and you cannot query posts by parent.

The big question is what you'd like to display when accessing a single post...

if you want to display the main site navigation yuo can do this:

<div id="dep-menu">
<?php global $post;
if (!is_front_page()) { // so I don't display a link on the homepage saying "Homepage"
    if (is_page()) {
        if($post->post_parent) { //if page has parent
            $children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0"); //include a link to the parent
            $children.= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); //add the child pages
        } else {
            $children = wp_list_pages("title_li=&include=".$post->ID."&echo=0");//parent link
            $children.= wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");//children
       }
    } else {
        $children = wp_list_pages("title_li=&echo=0&depth=1"); //list top level pages
    }
    if ($children) { ?>
        <ul>
        <?php echo $children; ?>
        </ul>
    <?php }
}
?>
</div>
share|improve this answer
    
I want to show the menu like it does on the page preceding it so if I was viewing a Covered Call Report post the menu would show Covered Call | Report ASX Recommendation | Trade History | US Recommendation as if it were a page. –  Joshua Mar 7 '12 at 1:14
    
i.e. you want to list the other posts in the same category. Am I right ? –  hannit cohen Mar 7 '12 at 9:28
    
I have edited OP to try and explain a little better –  Joshua Mar 7 '12 at 23:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.