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

  • SEARCH
  • Home
  • 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 8398117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:57:40+00:00 2026-06-09T20:57:40+00:00

I’m having a hard time working through the Walker_Nav_Menu docs . I want to

  • 0

I’m having a hard time working through the Walker_Nav_Menu docs. I want to have a walker that about puts the children of an element with certain id but i’m not sure exactly where to start.

I did some research but couldn’t find anything based off of a Page ID. Does any one have any links or references on how to get this to work?

Thanks for the info

  • 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-09T20:57:41+00:00Added an answer on June 9, 2026 at 8:57 pm

    Solved!

    I was looking a it all wrong, i was trying to compare post ID instead of menu ID

    here’s my full walker, modified version of Stephen Harris wp.tutsplus tutorial

    if you don’t pass an menu item ID it resorts to the current posts tree.

    <?php
    
    /* Walker Class for selecting only current nav children.
     * Modified version of Stephen Harris class that adds in support for selecting based on menu_item_id
     *
     * @param int $menu_item_id ID of the menu item you want to select off of (optional)
     *
     * @author Jake Chamberlain
     * @link http://jchamb.com
     * @author Stephen Harris
     * @link http://wp.tutsplus.com/tutorials/creative-coding/understanding-the-walker-class/
     */
    
    
    class Selective_Walker extends Walker_Nav_Menu
    {
        var $menu_item;
    
        function __construct($menu_item_id = false) {
    
            $this->menu_item = $menu_item_id;
        }
    
    
        // Don't start the top level
        function start_lvl(&$output, $depth=0, $args=array()) {
            if( 0 == $depth )
                return;
            parent::start_lvl($output, $depth,$args);
        }
    
        // Don't end the top level
        function end_lvl(&$output, $depth=0, $args=array()) {
            if( 0 == $depth )
                return;
            parent::end_lvl($output, $depth,$args);
        }
    
        // Don't print top-level elements
        function start_el(&$output, $item, $depth=0, $args=array()) {
            if( 0 == $depth && !$this->menu_item )
                return;
            parent::start_el($output, $item, $depth, $args);
        }
    
        function end_el(&$output, $item, $depth=0, $args=array()) {
           if( 0 == $depth && !$this->menu_item )
              return;
            parent::end_el($output, $item, $depth, $args);
        }
    
        // Only follow down one branch
        function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
    
             // Check if element as a 'current element' class
             $current_element_markers = array( 'current-menu-item', 'current-menu-parent', 'current-menu-ancestor' );
             $current_class = array_intersect( $current_element_markers, $element->classes );
    
             if( !$this->menu_item)
             {                      
                // If element has a 'current' class, it is an ancestor of the current element
                $ancestor_of_current = !empty($current_class);       
    
                // If this is a top-level link and not the current, or ancestor of the current menu item - stop here.
                if ( 0 == $depth && !$ancestor_of_current)
                    return;
    
                parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
             }
             else
             {       
                if ( $this->menu_item != $element->menu_item_parent )
                    return;
    
                 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
             }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.