-
AuthorPosts
-
January 16, 2015 at 2:28 am #380570
Do you have any code handy for adding the parent page (preferably linked) to the sidebar navigation. I like using the automated sidebar navigation, but it’d be nice if the parent page showed above the sub-menu list. For example, if I could have “About The FPR” show up at the top of the right sidebar on http://fpronline.org/about-the-fpr/strategy/ (preferably linked to http://fpronline.org/about-the-fpr/) , that would be nice :) Do you have a snippet for that handy?
Thanks!
January 16, 2015 at 6:03 pm #380936Hi sky19er!
Please add following code to Quick CSS in Enfold theme options under General Styling tab
.page-id-36 ul.nested_nav:before { content: 'About The FPR'; color: black; font-size: 18px; }
Best regards,
YigitJanuary 16, 2015 at 8:21 pm #381065Thanks, but that’s “semi-manual” ;) Then I’d have to add that for every page in the section and update it every time a page is added in the section, etc. Plus it doesn’t have the linking feature. I was hoping for something more automated, maybe via php / a child theme file? Thanks again.
January 18, 2015 at 9:14 am #381385Hi!
You can edit functions-enfold.php. Find this code on line 991:
$default_sidebar = false; $sidebar_menu .= "<nav class='widget widget_nav_menu $display_child_pages'><ul class='nested_nav'>"; $sidebar_menu .= $children; $sidebar_menu .= "</ul></nav>";
Replace it with:
$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 .= "<a href='{$parentlink}'>$parent</a>"; $sidebar_menu .= $children; $sidebar_menu .= "</ul></nav>";
Regards,
IsmaelJanuary 21, 2015 at 4:45 am #382867Thanks, Ismael — that looks like what I’m talkin’ ’bout! ;) And could you remind me how to handle that via a child theme? I have the child theme all set up and activated, but do i use functions-enfold.php in the child theme, or just functions.php? And what exactly would I include in the child theme file? I got it working by editing the functions-enfold file directly, but can’t seem to get it to work via the child theme. Thanks again!
January 21, 2015 at 6:05 pm #383215Hi!
functions-enfold.php file is not recognized in child theme, so you should add modified function into functions.php file of your child theme
Regards,
YigitJanuary 21, 2015 at 10:13 pm #383375Hmm, I’m still having issues — can’t seem to get the code right without causing an error — any chance you could tell me exactly what I’m supposed to put in the functions.php file of your child theme? Sorry to bug.
January 23, 2015 at 10:24 am #384272Hey!
You can copy the whole avia_sidebar_menu on the child theme’s functions.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; $sidebar_menu .= "<nav class='widget widget_nav_menu $display_child_pages'><ul class='nested_nav'>"; $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; } }
Do the modification above.
Cheers!
IsmaelJanuary 23, 2015 at 10:01 pm #384657Ahh, I had the `if(!function_exists(‘avia_sidebar_menu’))
{` in there, which seemed to break it — thank you!!!FYI, I added an h3.widgettitle to it, which I think is a nice touch:
$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>";
January 26, 2015 at 9:23 am #385301September 30, 2015 at 3:35 pm #511597Thanks for this thread. It would be fantastic if this option was part of the theme admin somehow. Those sidebars look so much better with the title/parent page.
October 1, 2015 at 5:50 am #511936December 8, 2016 at 11:22 pm #722238Hey 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.
For example, on http://besanthill.wpengine.com/academics/sustainability/calendar-and-news/ (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?
Thanks!December 9, 2016 at 1:32 pm #722405Hi!
please open a new ticket in our support forum, instead of posting in a very old thread about it.
Send us admin access, so we can have a deeper look into it.Regards,
Andy -
AuthorPosts
- The topic ‘add titles to sidebar navigation’ is closed to new replies.