Also having the same problem.
<u>My set-up looks like this:</u>
– Main menu has only top level items
– Advanced menu widget shows the next level and down of the selected parent item (Achieved with “Only related sub-items” and “Starting depth: 1”)
I have “Include parents” and “Post related parents” checked also
The main menu has:
– Catagory 1
and the advanced menu show’s the following children when Category 1 is selected:
– Sub category 1
– Sub category 2
But viewing posts in either Sub category doesn’t render the advanced menu at all
I need to do the same thing. I have a parent category called Newsroom, and two sub categories called News and Press Releases. When I look at the category page for either News or Press releases, the Advanced menu widget shows the correct menu. However, if I view a post within either sub category, the Advanced menu widget shows an empty menu.
I have a fix that isn’t pretty but it did the job for my site…
in the following file
advanced-menu-widget/advanced-menu-widget.php
look for the following block of code near the bottom of the Walk method
// descend only on current tree
$descend_test = array_intersect( $current_element_markers, $e->classes );
if ( empty( $descend_test ) && !$this->direct_path ) {
unset ( $children_elements );
}
comment out the unset line so it looks like this
// descend only on current tree
$descend_test = array_intersect( $current_element_markers, $e->classes );
if ( empty( $descend_test ) && !$this->direct_path ) {
//unset ( $children_elements );
}
[Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
I always try and avoid modifying plugins so I can get updates.
I was able to solve it a different way, though it’s not very pretty either. I used the built-in Custom Menu widget and using CSS hid the items I didn’t want to show. The Custom Menu widget shows the entire menu hierarchy, so you can select items that aren’t related to the current page/post and hide them via CSS. In the end it produces the same results as Advanced Menu Widget, but will also show the proper items on a post.
I’m not thrilled that there is HTML rendering for all the menu items that I’m hiding, but this will work well enough for now.
Thank you both for your answers.
Spencermefford, the problem with your fix, is that it’s not really beneficial for seo if I’m not mistaken..
As for harveyharveyharvey, I think you put twice the same code. Can you please show in which part of the file should I add your fix plz?
Thanks a lot!
Sorry for not making it clear.
I posted a larger block of code to help you find it. You only need to comment out one line from that block…
// descend only on current tree
$descend_test = array_intersect( $current_element_markers, $e->classes );
if ( empty( $descend_test ) && !$this->direct_path ) {
//unset ( $children_elements );
}
You’ll find the block of code near the bottom of the function called walk. Again only need to comment out the one “unset” line as show in bold above
Think I also had to change the “Show hierarchy:” setting to “Only strictly related sub-items”
This is working well, thanks a lot!
If I do this, the entire menu disappears… anyone else?
It may be because of your menu configuration
Have you got “Only related sub-items”, “Include parents” and “Post related parents” checked?