• I’m trying to generate a page tree submenu list based on the currently active top page level. The comlete page tree is as follows:

    1.0.0 top page item
    – 1.1.0 child page item
    – – 1.1.1 grandchild page item
    – – 1.1.2 grandchild page item
    – 1.2.0 child page item
    – – 1.2.1 grandchild page item
    – – 1.2.2 grandchild page item
    – 1.3.0 child page item
    – – 1.3.1 grandchild page item
    – – 1.3.2 grandchild page item

    2.0.0 top page item
    3.0.0 top page item

    (Second and third top page items have similar hierarchy)

    I want the page tree in my sidebar.php with the following behaviour:

    • Only the currently active top page with all its children and all their grandchildren expanded when navigating this spesific top page branch
    • Current page item and current parent highlighted.
    • Other top page items are hidden

    I short this means that the whole sidebar menu changes when moving between top pages but remains unchanged within the branch/navigation of a each top page down to single page.

    Furthermore I’m like to display the page items by menu order.

    Does anyone have a code snippet og thought on how to achieve this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter André Giæver

    (@iwasfirst)

    Ah, I managed to solve it. Initially I couldn’t figure out where the current page item class had gone. It worked at single page level but not at parent or ancestor level. I had to insert the following right before the sidebar inclusion in the template:
    <?php wp_reset_query(); ?>
    This flushed out that bug.

    Secondly i chose to hide all page items with css display:none; and only show page items with the class current_page_item, current_page_parent and current_page_ancestor with display:block;.

    Last but not least here’s the code for getting the page list located in my sidebar:
    <?php wp_list_pages('sort_column=menu_order'); ?>

    That’s it and that’s that!

    Works perfectly!

    However, I’m no php guru so if anyone can present me with a more graceful approach I’ all ears!

    hi

    I need some difference between pages and menus….?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dynamically generate submenu based on parent page’ is closed to new replies.