-
AuthorPosts
-
November 15, 2019 at 4:49 pm #1157221
Hi,
I have read this thread: https://kriesi.at/support/topic/show-parent-page-above-nested-subpages-in-sidebar-navigation/ and this one: https://kriesi.at/support/topic/show-parent-page-above-nested-subpages-in-sidebar-navigation-2/
I’d like to link the parent above the nested subpages in my right sidebar. This is the code for it:
$sidebar_menu .= "<a href='". get_the_permalink($parent) ."'>".get_the_title($parent)."</a>";
and at the same time I want to keep the layout as I defined in my css, using this code:
$sidebar_menu .= '<span>'.get_the_title($parent).'</span>';
How can I combine these two?
On the page shown in the private data you see in the right side bar the word “AANMELDEN”. This is the word I want to link to the corresponding page.
November 16, 2019 at 3:53 pm #1157484Hey JantienM,
You can use the upper line and wrap the lin in the span too.
If you need further assistance please let us know.
Best regards,
VictoriaNovember 17, 2019 at 11:42 am #1157606Hi Victoria,
I’m sorry, my knowledge of this kind of coding is lacking. I tried this, but get an error then:
$sidebar_menu .= "<a href='". get_the_permalink($parent) ."'>" '<span>'.get_the_title($parent).'</span>' "</a>";
Where do I place the span code exactly?
November 17, 2019 at 10:05 pm #1157691Hi,
Your code was a little off, I found this to work:
$sidebar_menu .= "<a href='". get_the_permalink($parent) ."'> <span class='parent_nav_menu'>".get_the_title($parent)."</span></a>";
notice I added a custom class “parent_nav_menu” to help with styling it with css, if you choose to.
I’m using a child theme so I put this code in my child theme 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 .= "<a href='". get_the_permalink($parent) ."'> <span class='parent_nav_menu'>".get_the_title($parent)."</span></a>"; $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; } }
If you are not using a child theme, try the step in the post note that line numbers are probably wrong so search by text.
Best regards,
MikeNovember 19, 2019 at 10:08 am #1158081Thanks a lot Mike,
That works!
I also added this code to make sure the link doesn’t have an underline when hovering:
.inner_sidebar a:hover { text-decoration: none; }
November 19, 2019 at 1:28 pm #1158156Hi,
Thanks for sharing your modification, I’m sure this will help others 🙂
We will close this now. Thank you for using Enfold.For your information, you can take a look at Enfold documentation here
For any other questions or issues, feel free to start new threads in the Enfold forum and we will gladly try to help you :)Best regards,
Mike -
AuthorPosts
- The topic ‘Link parent page above nested subpages in sidebar navigation’ is closed to new replies.