-
AuthorPosts
-
July 20, 2019 at 4:22 am #1120376
Hello, Enfold support. I love the theme. I just have one major issue that I can’t, for the life of me, figure out. It’s been bothering me for months now. Perhaps it is much more complicated than it seems. I’ve searched through the forums and nothing has helped me thus far. I’ve been working with the Child theme for a while as well. Everything has worked on it–except this very issue.
I know that pages, when set to a parent category, will highlight that parent category on the header. Example, all pages set to the parent “destinations” will highlight the “destinations” in the menu. And all subpages will do the same if I set the parent accordingly.
However, unlike pages, posts do not have the option to set a parent page. Therefore, ALL posts go to the “Blog” page even though I specifically set the category to “Destinations.” I do not want this, of course. Posts related to destinations should highlight the Destinations menu and not the Blog menu.
My question is simple: How do I get a specific post to be highlighted under a specific main menu/header item. Example: I want all posts marked as the “Destinations” category to highlight “Destinations” in the main menu. Similarly, if I create a new menu page (labeled “CRAP”), I would want all posts under the “Crap” category to highlight “CRAP” in the main menu. It would allow for much better structuring of a site. Please help me resolve this matter.
Thank you
July 21, 2019 at 1:20 am #1120536Hey acelam714,
I believe that adding the categories classes to each post will allow you to highlight as needed;
Try adding this code to the end of your functions.php file in Appearance > Editor:add_filter( 'body_class', 'add_category_class' ); function add_category_class( $classes ) { if( is_single() && has_category('news') ) $classes[] = 'news-cat'; if( is_single() && has_category('writers') ) $classes[] = 'writers-cat'; return $classes; }
you will note this already has two classes for two categories as an example, please adjust to suit and add more as needed.
Best regards,
MikeJuly 21, 2019 at 4:29 am #1120557Hello, Mike. The code does not seem to work. Everything still shifts over to “Blog” regardless. Does capitalization matter? The header menu is all capitalized (DESTINATIONS) whereas the category itself only capitalizes the first letter (Destinations). I’ve tried all variations of capitalization as well and it still didn’t work. I inputted the following version of the code into the Child Theme’s functions.php area.
add_filter( ‘body_class’, ‘add_category_class’ );
function add_category_class( $classes ) {
if( is_single() && has_category(‘destinations’) ) $classes[] = ‘destinations-cat’;
return $classes;
}Is there something else that we are missing? I feel this is slightly more problematic than it should be. The code makes sense (is_single for only posts and the specific category), but it’s still not working. Is there something else we can try?
July 21, 2019 at 5:51 am #1120566Hi,
This code is working for me, please include an admin login in the Private Content area so we can examine.Best regards,
MikeJuly 21, 2019 at 5:50 pm #1120662Sure thing, Mike. Thank you for helping.
July 21, 2019 at 8:09 pm #1120691Hi,
I took a look at your posts in the category “Destinations” both inside the Advanced Layout Builder and the Classic Editor, and it seems to work fine.
So now that each page has “destinations-cat” added to it we can add this css to change the menu highlighted items:#top.destinations-cat .avia-menu li.current-menu-item { background-color: transparent !important; border: 0px solid #ffffff!important; } #top.destinations-cat #header .av-main-nav > li.current-menu-item > a .avia-menu-text { color: #fff !important; } #top.destinations-cat .avia-menu li#menu-item-2165 { background-color: #f2f3ff !important; border: 1px solid #ffffff!important; border-radius: 100px !important; } #top.destinations-cat #header .av-main-nav > li#menu-item-2165 > a { color: #109bc5 !important; }
I added this, please clear your browser cache and check.
Best regards,
MikeJuly 21, 2019 at 9:33 pm #1120706When I hover the mouse over the word “Blog” there is no hover state. That makes me think we somehow masked but didn’t resolve the issue, because it’s messing up the hover state for the “Blog” menu.
I’m slightly concerned the problem will manifest itself in other ways if not actually resolved. Is there anyway to fix that? As in, keep the destinations active state while restoring the hover state over the “Blog” menu item? Perhaps figuring that out will solve the problem once and for all.
July 21, 2019 at 11:16 pm #1120714Hi,
Please try adding this css:#top.destinations-cat .avia-menu li.current-menu-item:hover { background-color: #f2f3ff !important; border: 1px solid #ffffff!important; border-radius: 100px !important; } #top.destinations-cat .avia-menu li.current-menu-item a:hover,#top.destinations-cat #header .av-main-nav > li.current-menu-item:hover > a .avia-menu-text { color: #109bc5 !important; }
Best regards,
MikeJuly 22, 2019 at 12:44 am #1120721Thank you so much, Mike. Your help has been amazing. Please let me know if I understand this correctly. Suppose I have a menu header item and category called “Stuff” in the future, I would do the following.
put into function.php’s previous block of code.
if( is_single() && has_category(‘stuff’) ) $classes[] = ‘stuff-cat’;
put into custom css
#top.stuff-cat .avia-menu li.current-menu-item {
background-color: transparent !important;
border: 0px solid #ffffff!important;
}
#top.stuff-cat #header .av-main-nav > li.current-menu-item > a .avia-menu-text {
color: #fff !important;
}#top.stuff-cat .avia-menu li#menu-item-2165 {
background-color: #f2f3ff !important;
border: 1px solid #ffffff!important;
border-radius: 100px !important;
}
#top.stuff-cat #header .av-main-nav > li#menu-item-2165 > a {
color: #109bc5 !important;
}#top.stuff-cat .avia-menu li.current-menu-item:hover {
background-color: #f2f3ff !important;
border: 1px solid #ffffff!important;
border-radius: 100px !important;
}#top.stuff-cat .avia-menu li.current-menu-item a:hover,#top.stuff-cat #header .av-main-nav > li.current-menu-item:hover > a .avia-menu-text {
color: #109bc5 !important;
}July 22, 2019 at 1:47 am #1120728Hi,
That looks right. Unless there is anything else we can assist with on this issue, shall we close this then?Best regards,
MikeJuly 22, 2019 at 2:12 am #1120732I have only two questions left out of curiosity. Why is the code below broken up like that (the color: #109bc5 in a separate function instead of being grouped with background color, border, and radius? I noticed the same pattern with the hover state.
#top.stuff-cat .avia-menu li#menu-item-2165 {
background-color: #f2f3ff !important;
border: 1px solid #ffffff!important;
border-radius: 100px !important;
}#top.stuff-cat #header .av-main-nav > li#menu-item-2165 > a {
color: #109bc5 !important;
}And is 2165 just an enfold thing? Thank you.
July 22, 2019 at 3:44 am #1120735Hi,
The color is targeting the link, while the other css is targeting the li
The 2165 is part of the item ID, every ID must be different, thus the numbering.Best regards,
MikeJuly 22, 2019 at 6:17 am #1120751Thank you for all your assistance, Mike.
July 22, 2019 at 3:35 pm #1120879Hi acelam714,
Glad we could help :)
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.