Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #659972

    Is there a way to add the parent page name to the top of the auto-generated sidebar menu? See the link in the Private Content area. In this example, we would like “Trusts & Estates” to appear above “Core Documents, Family Matters, Real Estate, etc.”

    Thanks!

    #660860

    Hey John,

    Please add following code to functions.php file of your child theme

    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;
                    $sidebar_menu .= "<nav class='widget widget_nav_menu $display_child_pages'>
    <ul class='nested_nav'>";
                    $sidebar_menu .= get_the_title( $post->post_parent );
                    $sidebar_menu .= $children;
                    $sidebar_menu .= "
    </nav>";
                }
            }
    
            $sidebar_menu = apply_filters('avf_sidebar_menu_filter', $sidebar_menu, $args, $post);
    
            if($echo == true) { echo $sidebar_menu; } else { return $sidebar_menu; }
        }

    Best regards,
    Yigit

    #682336

    The code above works to display the parent page title in the sidebar, but how do you make it link to the actual page, and how do you target it for styling the css differently from the sub-pages?

    #682720

    Hi!

    Please use the code as following

    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);
                $permalink = get_permalink($post->post_parent); 
    
                if ($children)
                {
                    $default_sidebar = false;
                    $sidebar_menu .= "<nav class='widget widget_nav_menu $display_child_pages'>
    <ul class='nested_nav'>";
                    $sidebar_menu .= "<a class='avia-parent-title' href='".$permalink."''>".get_the_title( $post->post_parent )."</a>";
                    $sidebar_menu .= $children;
                    $sidebar_menu .= "
    </nav>";
                }
            }
    
            $sidebar_menu = apply_filters('avf_sidebar_menu_filter', $sidebar_menu, $args, $post);
    
            if($echo == true) { echo $sidebar_menu; } else { return $sidebar_menu; }
        }

    Then add following code to Quick CSS in Enfold theme options under General Styling tab
    a.avia-parent-title { color: orange; }

    Regards,
    Yigit

    • This reply was modified 7 years, 7 months ago by Yigit.
    #682928

    Thank you, that worked great.

    #683175

    Hi,

    Glad it worked for you! :)

    We will keep the thread open and will wait to hear from the creator of this thread. If you have any other questions or issues, please feel free to start a new thread.

    Best regards,
    Yigit

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.