Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8424945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:08:35+00:00 2026-06-10T04:08:35+00:00

I’m trying to create a sidebar navigation menu that changes based on the current

  • 0

I’m trying to create a sidebar navigation menu that changes based on the current location in the site.

Here’s what the navigation looks like as a whole:

  • Home
  • About us
    • Level 1a
    • Level 1b
    • Level 1c
  • Programs
    • Level 1d
      • Level 2a
      • Level 2b
    • Level 1e
      • Level 2c
      • Level 2d
    • Level 1f
  • Contact Us

Currently I’m using custom nav menus to create menus for the Home page so they can edit the custom menu via the menus link in the admin panel. They don’t want a sidebar nav menu on the contact page.

When on the about us page, they want the sidebar nav to look like this:

  • Level 1a
  • Level 1b
  • Level 1c

When on the Programs page, they want it to look like this:

  • Level 1d
  • Level 1e
  • Level 1f

When on Level 1d page, they want it to look like this:

  • Level 1d
    • Level 2a
    • Level 2b
  • Level 1e
  • Level 1f

making sure the the child pages only show for the current parent.

When on the Level 2a page, they want it to look the same as if on Level 1d page:

  • Level 1d
    • Level 2a
    • Level 2b
  • Level 1e
  • Level 1f

Also important to note is that I need to be able to style the current-page list-item differently than the rest of the items, so there’ll need to be some sort of current-page-item class added to that list item each time.

so far I have not been able to print only the children of the current parent when on Level 1d. wp_list_pages allows you to set the depth, but not limit it to only the current parent. It prints the children for all siblings as well (i.e. if on level 1d it prints all the level 2 children under their respective parents instead of only the level 2 children under the currently active parent).

How would I do this?

    <?php $current_section = "";
        if(is_front_page()):
             $current_section = "home";
             $nav_args = array(
                 'theme_location' => $current_section,
                  'container' => 'nav',
                  'container_class' => 'side-nav'
             );
             wp_nav_menu( $nav_args );
        else:

        endif;?>

This is what I have at this point. I’ve removed all the code in the else block because it wasn’t working anyway.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:08:36+00:00Added an answer on June 10, 2026 at 4:08 am

    Here’s the code I came up with:

        <?php
                $children = wp_list_pages('depth=1&title_li=&child_of='.$post->ID.'&echo=0');
                $current_page = wp_list_pages('title_li=&include='.$post->ID.'&echo=0');
                $grandparent=0;
                if($post->post_parent):
                    $parent = wp_list_pages('title_li=&include='.$post->post_parent.'&echo=0');
                    $siblings = wp_list_pages('depth=1&title_li=&child_of='.$post->post_parent.'&exclude='.$post->ID.'&echo=0');
                    $parent_children = wp_list_pages('depth=1&title_li=&child_of='.$post->post_parent.'&echo=0');
                    $parent_post = get_post($post->post_parent);
                    $grandparent = $parent_post->post_parent;
                    $parent_siblings = wp_list_pages('depth=1&title_li=&child_of='.$grandparent.'&echo=0&exclude='.$post->post_parent);
                endif;
                if(!$post->post_parent && $children):?>
                    <ul class="menu">
                        <?php echo $children;?>
                    </ul>
                <?php elseif($post->post_parent && $children):?>
                    <ul class="menu">
                        <?php echo $current_page;?>
                        <ul class="menu">
                            <?php echo $children;?>
                        </ul>
                        <?php echo $siblings;?>
                    </ul>
                <?php elseif($grandparent && $post->post_parent && !$children):?>
                    <ul class="menu">
                        <?php echo $parent;?>
                        <ul class="menu">
                        <?php echo $parent_children;?>
                        </ul>
                        <?php echo $parent_siblings;?>
                    </ul>
                <?php elseif(!$grandparent && $post->post_parent && !$children):?>
                    <ul class="menu">
                        <?php echo $parent_children;?>
                    </ul>
                <?php endif;?>
    

    It’s not the most elegant solution ever, but at least it does what I asked. The only thing that would improve on the actual functionality of this is to keep the order of the menu items while still allowing for sub menus. This code removes the menu item with a sub-menu and moves it to the top. I couldn’t figure out any other way to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.