Ready to get started?Download WordPress


Creating a sidebar menu for the parent of a selected page (2 posts)

  1. bowsting
    Posted 11 months ago #

    I am struggling with making what I am envisioning into a reality and I hope you all can help me with that.

    I am attempting to put a sort of menu in my sidebar but I would like it to be specific to the "parent" of the current page. I put parent in quotes because this is not the true parent of the page. In the current menu structure I have some pages occurring twice under different parents and what I would like to happen is that the menu hierarchy displayed is of that of the menu it was found under. Obviously the issue there is reading the state of which menu item it was selected under is not straight forward

    Additionally, I want the menu displayed on sub-sub-pages to still be the top level parent of which there will be about 5.

    In summary, I have about 5 main menu items. When a page is selected, I want one of these 5 items and the pages below them to display in the sidebar. When a page that falls under multiple main menu items is selected, I want the menu item that was used to select it to appear in the sidebar.

    Any help you can lend me in this would be greatly appreciated. Thank you!

  2. Jivani Bharat
    Posted 11 months ago #

    `<?php if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent);
    $children = wp_list_pages("title_li=&child_of=".$post->ID);

    if ($children) { echo $children; } ?>

    you can try about code i hope to usefull


You must log in to post.

About this Topic