Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Currently I am displaying posts based on category on a page, this page has custom side menu, which lists all the news articles, once a user clicks on the news title it takes it to that post display the full article, what i would like to do is keep the same menu that i had on my page and have it displayed on my single.php page as well, can i do this or is this is done without the use of sidebar?

Here is the function I'm using to display my menu:

function hierarchical_submenu($post) {
    $top_post = $post;
    // If the post has ancestors, get its ultimate parent and make that the top post
    if ($post->post_parent && $post->ancestors) {
        $top_post = get_post(end($post->ancestors));
    }
    // Always start traversing from the top of the tree
    return hierarchical_submenu_get_children($top_post, $post);
}

function hierarchical_submenu_get_children($post, $current_page) {
    $menu = '';
    // Get all immediate children of this page
    $children = get_pages('child_of=' . $post->ID . '&parent=' . $post->ID . '&sort_column=menu_order&sort_order=ASC');
    if ($children) {
        $menu = "\n<ul>\n";
        foreach ($children as $child) {
            // If the child is the viewed page or one of its ancestors, highlight it
            if (in_array($child->ID, get_post_ancestors($current_page)) || ($child->ID == $current_page->ID)) {
                $menu .= '<li class="sel"><a href="' . get_permalink($child) . '" class="sel current-item">' . $child->post_title . '</a>';
            } else {
                $menu .= '<li><a href="' . get_permalink($child) . '">' . $child->post_title . '</a>';
            }
            // If the page has children and is the viewed page or one of its ancestors, get its children
            if (get_children($child->ID) && (in_array($child->ID, get_post_ancestors($current_page)) || ($child->ID == $current_page->ID))) {
                $menu .= hierarchical_submenu_get_children($child, $current_page);
            }
            $menu .= "</li>\n";
        }
        $menu .= "</ul>\n";
    }
    return $menu;
}
share|improve this question

closed as too localized by toscho Feb 18 at 23:32

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

You would just include the same sidebar as you did on the page that was displaying the posts based on a category.

share|improve this answer
I didn't use sidebars for my pages, instead I used a modified get_pages based function the display all the menu items based on my page, but that doesn't work on the single.php file, I'm curious as to how others have tackled this problem. – user4304 Oct 28 '11 at 0:39
can you post the get_pages code you used? – Sagive SEO Oct 28 '11 at 5:15
See my original post, I've added the code there. – user4304 Oct 28 '11 at 23:29
WordPress 3.5 generates a notice now, Notice: Indirect modification of overloaded property WP_Post::$ancestors has no effect in /Applications/MAMP/htdocs/Site/wp-content/themes/myTheme/functions.php on line 316 and line 316 is: $top_post = get_post(end($post->ancestors)); – user4304 Dec 13 '12 at 22:05

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