Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #967378

    I’ve been using the code below to add titles to the auto sidebar menus. I see a comment in there — “hide or show child pages in menu” — can you tell me what I have to do to show the child pages? Thanks!

    function avia_sidebar_menu($echo = true)
        {
            $sidebar_menu = "";
    
            $subNav = avia_get_option('page_nesting_nav');
      
            
            $the_id = @get_the_ID();
            $args = array();
    		global $post;
    
            if($subNav && $subNav != 'disabled' && !empty($the_id) && is_page())
            {
                $subNav = false;
                $parent = $post->ID;
                $sidebar_menu = "";
    
                if (!empty($post->post_parent))
                {
                    if(isset($post->ancestors)) $ancestors  = $post->ancestors;
                    if(!isset($ancestors)) $ancestors  = get_post_ancestors($post->ID);
                    $root	= count($ancestors)-1;
                    $parent = $ancestors[$root];
                }
    
                $args = array('title_li'=>'', 'child_of'=>$parent, 'echo'=>0, 'sort_column'=>'menu_order, post_title');
    
                //enables user to change query args
                $args = apply_filters('avia_sidebar_menu_args', $args, $post);
    
                //hide or show child pages in menu - if the class is set to 'widget_nav_hide_child' the child pages will be hidden
                $display_child_pages = apply_filters('avia_sidebar_menu_display_child', 'widget_nav_hide_child', $args, $post);
    
                $children = wp_list_pages($args);
    
                if ($children)
                {
    
    				$default_sidebar = false;
    				$parent = get_the_title($post->post_parent);
    				$parentlink = get_the_permalink($post->post_parent);
    				$sidebar_menu .= "<nav class='widget widget_nav_menu $display_child_pages'><ul class='nested_nav'>";
    				$sidebar_menu .= "<h3 class='widgettitle'><a href='{$parentlink}'>$parent</a></h3>";
    				$sidebar_menu .= $children;
    				$sidebar_menu .= "</ul></nav>";
                }
            }
    
            $sidebar_menu = apply_filters('avf_sidebar_menu_filter', $sidebar_menu, $args, $post);
    
            if($echo == true) { echo $sidebar_menu; } else { return $sidebar_menu; }
        }
    #967409

    Sorry, false alarm, I guess I figured that out — I just removed the class in the function, right below that comment, so the code now looks like as shown below. But that didn’t handle what I was hoping it would also solve which is, once I click on a child page, the menu title changes to the parent of that child. Is there a way to tweak this code so that the title doesn’t change when you click on the child (i.e., so the menu/section title stays the same for the whole section)? Maybe you want me to start a new thread for this?

    function avia_sidebar_menu($echo = true)
        {
            $sidebar_menu = "";
    
            $subNav = avia_get_option('page_nesting_nav');
      
            
            $the_id = @get_the_ID();
            $args = array();
    		global $post;
    
            if($subNav && $subNav != 'disabled' && !empty($the_id) && is_page())
            {
                $subNav = false;
                $parent = $post->ID;
                $sidebar_menu = "";
    
                if (!empty($post->post_parent))
                {
                    if(isset($post->ancestors)) $ancestors  = $post->ancestors;
                    if(!isset($ancestors)) $ancestors  = get_post_ancestors($post->ID);
                    $root	= count($ancestors)-1;
                    $parent = $ancestors[$root];
                }
    
                $args = array('title_li'=>'', 'child_of'=>$parent, 'echo'=>0, 'sort_column'=>'menu_order, post_title');
    
                //enables user to change query args
                $args = apply_filters('avia_sidebar_menu_args', $args, $post);
    
                //hide or show child pages in menu - if the class is set to 'widget_nav_hide_child' the child pages will be hidden
                $display_child_pages = apply_filters('avia_sidebar_menu_display_child', $args, $post);
    
                $children = wp_list_pages($args);
    
                if ($children)
                {
    
    				$default_sidebar = false;
    				$parent = get_the_title($post->post_parent);
    				$parentlink = get_the_permalink($post->post_parent);
    				$sidebar_menu .= "<nav class='widget widget_nav_menu $display_child_pages'><ul class='nested_nav'>";
    				$sidebar_menu .= "<h3 class='widgettitle'><a href='{$parentlink}'>$parent</a></h3>";
    				$sidebar_menu .= $children;
    				$sidebar_menu .= "</ul></nav>";
                }
            }
    
            $sidebar_menu = apply_filters('avf_sidebar_menu_filter', $sidebar_menu, $args, $post);
    
            if($echo == true) { echo $sidebar_menu; } else { return $sidebar_menu; }
        }
    #969878

    Hi,

    Thank you for using Enfold.

    Where are you testing this? Please provide links to the parent and child page so that we can see the difference.

    Best regards,
    Ismael

    #970107

    You have to be logged into the admin to view the site (credentials in Private Content). I’m referring to the Annual Symposium section — http://03601fe.netsolhost.com/wordpress1/annual-symposium/. When someone clicks on the Photo Entries page — http://03601fe.netsolhost.com/wordpress1/annual-symposium/annual-photo-contest/photo-entries/ — I’d like the sidebar menu title to remain as Annual Symposium instead of changing to Photo Contest.

    Thanks and let me know if you have any other questions.

    #971483

    Hi,

    Thanks for the update. Please look for this line of code.

    $root	= count($ancestors)-1;
    $parent = $ancestors[$root];
    

    Replace it with..

    $parent = end($ancestors);
    

    Best regards,
    Ismael

    #971628

    Nice — perfect!! Thank you!!

    #972016

    Hi,

    Awesome! Glad we could help!

    Please take a moment to review our theme and show your support https://themeforest.net/downloads
    Don’t forget to bookmark Enfold Documentation for future reference.

    Thank you for using Enfold :)

    Best regards,
    Ismael

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘show child pages in menu’ is closed to new replies.