Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #722435

    Hey guys, I’m using this code you gave me on another site, but this site has some third level pages and, when I’m in one of those third level pages, the sidebar menu title changes to the parent of those third level pages — I need it to stay as the title of the section; the top level nav item; much more standard. Here’s the code that goes in the functions.php via my child theme….

    <?php
    
    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; }
        }
    
    ?>

    For example, on http://besanthill.wpengine.com/academics/sustainability/calendar-and-news/ (hosted on WPengine) (hosted on WPengine) the menu title should be Academics, not Sustainability Education.

    Would you mind showing me what I have to tweak to achieve that? I’m including ftp credentials for you.
    Thanks!

    #723568

    Hey sky19er,

    Thank you for using Enfold.

    I’m trying to modify the code in the functions.php file but it’s not taking effect in the frontend. Did you install any kind of cache plugin? Please post the WP login credentials so that we can disable it while testing the page.

    Best regards,
    Ismael

    #723812

    I don’t think there’s any cache plugin in there. WP Engine has it’s own caching built in, but I didn’t have any problem seeing changes as I was tweaking the other custom code I have in there (for how archives are displayed). Anyway, I’ll pass you an admin user login now.

    Thanks!

    #724858

    Any progress, Ismael? The menu headers are now showing as broken code (see link below). My client is overseeing the site development, so I’d rather not leave that broken code there any longer. Thanks.
    https://www.evernote.com/shard/s320/sh/6180a239-0ac0-44fe-9069-246133e9ab68/2a6da15b45fe5eba48cf955baea0e1db

    #725129

    OK, I just made a copy of your file and named it functions-ismael.php and re-uploaded the version from before you were in there — I had to at least get rid of that bit of code that was showing instead of the widget titles. Please give me an update when you can. Thanks.

    #725659

    Hi,

    I’m sorry for the late response. We modified the code in the functions.php file. Please remove browser or hard refresh before checking the page.

    Best regards,
    Ismael

    #725694

    Great — thank you so much!!

    #727366

    Hi,

    No problem. Let us know if you need anything else.

    Best regards,
    Ismael

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘adding titles to auto sidebar menus’ is closed to new replies.