-
AuthorPosts
-
July 12, 2016 at 4:46 pm #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!
July 14, 2016 at 2:37 pm #660860Hey 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,
YigitSeptember 5, 2016 at 8:15 pm #682336The 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?
September 6, 2016 at 4:45 pm #682720Hi!
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 8 years, 3 months ago by Yigit.
September 7, 2016 at 5:17 am #682928Thank you, that worked great.
September 7, 2016 at 2:49 pm #683175 -
AuthorPosts
- You must be logged in to reply to this topic.