• Hi,
    This is a tricky one.

    I’m working on a theme which has three separate categories.

    There is no “News” or “Blog” section to the site, instead each of the categories act as their own mini-blog’s relevant to three various sections of the site.

    When a user clicks on these pages, I want the sidebar to remain showing the section that the user is in. To achieve this, I have pages set up with specific templates selected, and these templates then pull in their relevant content as well as snippets of the posts. All good so far. However, if the user clicks on a post and is then taken to the post page, the menu in the sidebar doesn’t work and the main menu active link is lost as the post is now unaware that it is a child of a category which is itself within a page. I tried using this code-

    <div id="sidenav">
    
            <p class="title">
            <?php
            $ancestors = get_post_ancestors($post->ID);
            $root = count($ancestors)-1;
            $parent = $ancestors[$root];
            $parent_title = get_the_title($parent);?>
            <a href="<?php echo get_permalink($parent) ?>"><?php echo $parent_title;?></a></p>
    
        <?php
            if ($post->post_parent)	{
            $ancestors=get_post_ancestors($post->ID);
            $root=count($ancestors)-1;
            $parent = $ancestors[$root];
            } else {
            $parent = $post->ID;
            }
            $children = wp_list_pages("title_li=&child_of=". $parent ."&echo=0");
            if ($children) { ?>
            <ul>
                <?php echo $children; ?>
                <?php } ?>
            </ul>
    
        <?php if ($post->post_parent)	{
            $ancestors=get_post_ancestors($post->ID);
            $root=count($ancestors)-1;
            $careersparent = $ancestors[$root];
        } else {
            $careersparent = $post->ID;
        } ?>
    
        </div>

    However this won’t work, because as I said as far as the post is concerned, it’s ancestor is it’s category.

    Any idea’s?

    Thanks in advance.

  • The topic ‘Force a Category and It's Posts to behave like children of a page.’ is closed to new replies.