-
AuthorPosts
-
March 1, 2019 at 12:11 pm #1073095
Hi,
I’m building left sidebar menu and want parent menu items to stay highlighted when a subitem is opened.
So far I’ve managed to get this working for Pages, Blog, Shop and Portfolio.
/* change active menu item background and color */ /* this works for PAGES with subpages */ .current_page_item a { color: #719430; } /* highlight SHOP menu item when product item open */ .single-product .main_menu ul li#menu-item-643 a .avia-menu-text { color: #719430; }
I have 2 Portfolio menu entries (of course based on Portfolio categories), say A and B.
With the css below I get it working but now on any open portfolio item it highlights both portfolio categories…/* WORKS BUT HIGHLIGHTS BOTH PORTFOLIOS (CATS) */ /* highlight Portfolio menu item when portfolio item open */ body.single-portfolio .main_menu ul li#menu-item-765 a .avia-menu-text { color: #719430; } /* WORKS BUT HIGHLIGHTS BOTH PORTFOLIOS (CATS) */ /* highlight Portfolio menu item when portfolio item open */ body.single-portfolio .main_menu ul li#menu-item-764 a .avia-menu-text { color: #719430;
Is it possible to restrict the highlight to just the portfolio category the item belongs to?
Perhaps with an adaptation of the solution for previous-next in portfolio cats in functions.php which I found on this forum?/* make previous-next buttons stay within the relevant portfolio category (multiple portfolios) */ add_filter( 'avia_post_nav_entries', 'enfold_customization_postnav', 10, 2); function enfold_customization_postnav($entries, $settings) { if($settings['type'] == 'portfolio') { $settings['same_category'] = true; $entries['prev'] = get_next_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); $entries['next'] = get_previous_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); } return $entries; }
Thanks in advance for your help!
- This topic was modified 5 years, 8 months ago by rob2701. Reason: forgot to enter code blocks
March 1, 2019 at 12:12 pm #1073100Hey Rob!
Thanks for contacting us!
Could you please share a link to your page so we can see the issue in action?
Cheers!
YigitMarch 1, 2019 at 12:21 pm #1073111Hi Yigit,
Unfortunately not yet possible, still working on a local development server and have not yet set up the reverse proxy.
Rob
March 1, 2019 at 1:43 pm #1073173Hi,
I understand. Could we please take a look when your website is publicly accessible? Otherwise i am afraid reproducing the issue on our local installation might not be easily possible and forums are currently very busy
Best regards,
YigitMarch 1, 2019 at 2:08 pm #1073189Hi Yigit,
Publicly accessible is a bit difficult (site is live on a different URL), I’m just starting to rebuild a local better version to transport afterwards. Still very early stages as I’m still learning how Enfold works.
But I can give you access to the devsite once I get that damn reverse proxy running.The issue is not that difficult to reproduce:
– build two portfolios (categories) en give them each a menu entry on a left sidebar menu
– set each portfolio to display one cat only
– enter some portfolio items in each category
– enter CSS above in child menu style
– open a portfolio item in one of the portfolio menu entries
– see both portfolio menu entries highlightedI understand you are all very busy now, so good luck with that tsunami of requests :-)
This is not that urgent for now.Thanks for your attention so far.
Best regards,
RobMarch 1, 2019 at 2:50 pm #1073209Hi Yigit,
I have the reverse proxy setup to the local devsite running, so it’s now accessible with password from the outside.
Let me know when you have time and are a little less busy, then I can create a temporary login without password link for you.
No hurry though (it’s just a dev site for now)
Rob- This reply was modified 5 years, 8 months ago by rob2701.
March 3, 2019 at 1:30 pm #1073941Switching to menu top I see that the breadcrumbs trail does it properly for the portflio items: it shows the portfolio category (parent) of the portfolio item. The menu highlighting however (with the above css) seems to get the grandparent instead, i.e. the whole portfolio, therefore highlighting all portfolio category menu items/taxonomies.
March 3, 2019 at 10:22 pm #1074053Hi,
I added this CSS below to clarify the problem.
There are 3 different portfolios (= categories/taxonomies).
– Each portfolio has a separate menu item (top level, not nested)
– Each portfolio grid on each page is restricted to display 1 portfolio category
– ALL portfolio items have been assigned a proper category
– ALL portfolio items have proper parent set for breadcrumbsProblem:
Even though the CSS “should” be restricted to each separate menu item ID, still on opening a portfolio item ALL portfolio cats/taxonomies/menu-entries get highlighted…When you can, please help me understand this behaviour, because I’m lost now.
/* -------------------------------------------------------------- */ /* TEST PORTFOLIO ITEM CAT PARENT HIGHLIGHT BELOW */ /* TEMP DIFFFENT COLOURS TO SEE THE DIFFERENCES */ /* Portfolio A - Menu ID = 765 */ /* hover over "Remove" button of menu item to see ID */ /* HIGHLIGHTS ALL PORTFOLIO CATS even while restricted to only this menu item */ /* highlight Portfolio menu item when portfolio item open */ body.single-portfolio .main_menu ul li#menu-item-765 a .avia-menu-text { /* color: #719430 !important; */ color: blue; } /* highlight bottom border when menu top header */ body.single-portfolio .main_menu ul li#menu-item-765 a { /* border-bottom: 2px solid #719430 !important; */ border-bottom: 2px solid blue; } /* Portfolio B - menu ID = 764 */ /* hover over "Remove" button of menu item to see ID */ /* HIGHLIGHTS ALL PORTFOLIO CATS even while restricted to only this menu item */ /* highlight Portfolio menu item when portfolio item open */ body.single-portfolio .main_menu ul li#menu-item-764 a .avia-menu-text { /* color: #719430 !important; */ color: orange!important; } /* highlight bottom border when menu top header */ body.single-portfolio .main_menu ul li#menu-item-764 a { /* border-bottom: 2px solid #719430 !important; */ border-bottom: 2px solid orange; } /* Portfolio C - menu ID = 1038 */ /* hover over "Remove" button of menu item to see ID */ /* HIGHLIGHTS ALL PORTFOLIO CATS even while restricted to only this menu item */ /* highlight Portfolio menu item when portfolio item open */ body.single-portfolio .main_menu ul li#menu-item-1038 a .avia-menu-text { /* color: #719430 !important; */ color: purple; } /* highlight bottom border when menu top header */ body.single-portfolio .main_menu ul li#menu-item-1038 a { /* border-bottom: 2px solid #719430 !important; */ border-bottom: 2px solid purple; }
- This reply was modified 5 years, 8 months ago by rob2701. Reason: corrected some typos
March 6, 2019 at 12:21 am #1075198Link to staging site in private content if you want to have a look. Thanks in advance.
March 7, 2019 at 5:31 am #1075750Hi,
Thank you for sharing the details and sorry for the late reply.
I checked your site and the parent menu “Info” gets highlighted when any of its child menu items are selected. Were you able to figure this out?
Let us know if you need any further assistance.
Best regards,
VinayMarch 7, 2019 at 11:04 am #1075911Hi Vinay,
Yes, like you can read above I figured out everything EXCEPT the portfolio items.
Can you please read above before responding? :-)
As you can see from the site, opening a PORTFOLIO item highlights ALL 3 portfolio menu items, even though the CSS says the colours are restricted to 1 portfolio menu item only…Regards,
RobSo to make it more clear:
Go to menu item “Golden Ratio” (menu item is set to highlight purple)
Open a portfolio item in there
See all 3 portfolio menu items highlighted (blue-orange-purple)
So the other 2 portfolios get highlighted as well, even though they are different portfolio categories on different pages with different menu items and different colors specified.- This reply was modified 5 years, 8 months ago by rob2701. Reason: Added explanation for clarity
March 9, 2019 at 6:55 pm #1076810Solved the issue myself gents. One less request in the flood :-)
Menu now highlights only the proper portfolio-cat/menu-item on opening a single portfolio item.
Here’s how I did it in case someone else meets the same problem:
Child theme functions.php:
// Highlight only proper portfolio CATEGORY/MENU ITEM when single portfolio item open // instead of all portfolio cats being highlighted function add_category_name($classes = '') { if(is_single()) { $category = get_the_terms($post->ID, 'portfolio_entries'); $classes[] = 'category-'.current($category)->slug; } return $classes; } add_filter('body_class','add_category_name');
Child theme Quick CSS:
/* highlight only proper Portfolio menu item (category) when single portfolio item open */ /* hover over "Remove" button of menu item to see the menu IDs */ body.single-portfolio.CATEGORY-SLUG-A .main_menu ul li#menu-item-765 a .avia-menu-text, body.single-portfolio.CATEGORY-SLUG-B .main_menu ul li#menu-item-764 a .avia-menu-text, body.single-portfolio.CATEGORY-SLUG-C .main_menu ul li#menu-item-1038 a .avia-menu-text { color: #719430 !important; } /* highlight bottom border when menu top header */ body.single-portfolio.CATEGORY-SLUG-A .main_menu ul li#menu-item-765 a, body.single-portfolio.CATEGORY-SLUG-B .main_menu ul li#menu-item-764 a, body.single-portfolio.CATEGORY-SLUG-C .main_menu ul li#menu-item-1038 a { border-bottom: 2px solid #719430 !important; }
You can close this request.
Kind regards,
Rob- This reply was modified 5 years, 8 months ago by rob2701. Reason: corrected small typo
March 11, 2019 at 12:31 am #1077162Hi,
Spoke too soon about closing the ticket… :)
Creating subcategories in one portfolio parent category I discovered some behaviour which I cannot seem to solve.Code above works fine as long as there are no subcategories, highlights menu parent perfectly.
However, when I add 3 subcategories under MenuItem/PortfolioCat A (A1,A2,A3) in order to have sorting, the behaviour becomes unpredictable:- in the portfolio grid I cannot just choose the parent Category-A, I have to choose to display A+A1+A2+A3, otherwise I get no sorting. Shouldn’t subcategories be included by default?
- however, now I get in the sorting all/subcatA1/subcatA2/subcatA3/catA… what is catA (the parent doing there? There is already ALL…
- If I only choose catA itself for the portfolio grid display, then of course I have proper menu highlighting but no sorting…
I appreciate any help or insight you can give me.
Thanks in advance,
RobMarch 11, 2019 at 11:37 am #1077272Hi,
Playing around with it some more, I have found that I need to choose only subcategories (children) for display. Then sorting works as it should. BUT: in my mind this is a bit of a convoluted workaround and it creates other problems.
Now I need to target each subcategory in the CSS separately to get proper menu highlighting. And the highlighting behaves as if it were a subMENU item (which it is not, it is just a subcategory in the portfolio with no menu item set for it), that is to say the highlight bottom color becomes attached directly to the menu text instead of being on the bottom of the header…And how do I solve that?
And what happens if I have another portfolio category B which has a subcategory name equal to the one in portfolio category A?I understand that it’s a difficult situation because the theme wants to give the user the liberty to freely choose any combination of portfolio categories to display in the grid. Fine if we’re only talking about parents (same level). But here we have 1 parent with a few children.
<spockmode on>The resulting behaviour is highly illogical, captain!</spockmode off>
This is what I have logically presented:
FRUITS
Apples
Pears
Bananas
Sweet
SourFirst:
I would expect that choosing FRUIT to display in the portfolio would include the subcategories.
After all, they are only for sorting purposes WITHIN the main portfolio cat. That’s why they are set as children.
But: I need to choose all children to get sorting below the parent. Doesn’t make sense (at least not to me). I would understand it if the children were parents also, but they’re not.Second:
This complicates matters enormously, because a “Granny Smith apple” would be:
Fruit / Apple / Sour, belonging to 3 categories (1 parent and 2 children).
Setting the subcats specifically to be CHILDREN should be enough for the display and the sorting to understand what it needs to do?So my question is:
Wouldn’t it be better and easier to have “parent includes children” as the default and then treat child exclusions as exceptions?
To my mind (and I am not a coder, mind you) this seems the opposite, i.e. catering for the exceptions and then ending up with an illogical default. Or, in other words, it seems parentA+childrenA1+A2+A3 is treated the same as parentA+parentE+parentG.
Supermarkets may put tomatoes with the vegetables, but they’re still technically a fruit :)Or maybe I’m doing something wrong not understanding the theme logic properly.
But please correct me if I’m wrong. I love to learn :)So long story short:
I solved the highlighting issue when there is no sorting enabled (only main portfolio category chosen for display).
Appreciate any help you can give me to sort out the highlighting menu bottom colour workaround (when sorting is enabled, i.e. subcategories chosen for display).Thanks in advance
RobMarch 12, 2019 at 8:46 pm #1077960Hi, here’s how I solved it in case someone else needs it too:
/* change active menu item background and color */ /* this works for PAGES with SUBPAGES */ .current_page_item a { color: #719430; } /* highlight SHOP menu item when product item open */ /* hover over "Remove" button of menu item to see menuID */ .single-product .main_menu ul li#menu-item-MENUID a .avia-menu-text { color: #000000; } /* highlight bottom border when menu top header */ .single-product .main_menu ul li#menu-item-MENUID a { border-bottom: 2px solid #719430; } /* highlight only proper Portfolio menu item (category) when single portfolio item open */ /* hover over "Remove" button of menu item to see the menuID */ /* because of subcategories for sorting now I have to specify each subcategory as well */ body.single-portfolio.category-A .main_menu ul li#menu-item-MENUID a .avia-menu-text, body.single-portfolio.category-A1SUB .main_menu ul li#menu-item-MENUID a .avia-menu-text, body.single-portfolio.category-A2SUB .main_menu ul li#menu-item-MENUID a .avia-menu-text, body.single-portfolio.category-A3SUB .main_menu ul li#menu-item-MENUID a .avia-menu-text, body.single-portfolio.category-B .main_menu ul li#menu-item-MENUID a .avia-menu-text { /* color: #719430 !important; */ color: #000000 !important; } /* highlight bottom border when menu top header */ body.single-portfolio.category-A .main_menu ul li#menu-item-MENUID a { border-bottom: 2px solid #719430 !important; } /* because of subcategories for sorting need to specify each subcategory as well */ body.single-portfolio.category-A1SUB .main_menu ul li#menu-item-MENUID a, body.single-portfolio.category-A2SUB .main_menu ul li#menu-item-MENUID a , body.single-portfolio.category-A3SUB .main_menu ul li#menu-item-MENUID a { border-bottom: 2px solid #719430 !important; }
The bottom border parts are only valid if you use top menu of course.
When you have time I’d be very interested in your answer on:
- why I need to choose all portfolio subcategories (without the parent) in the portfolio grid in order to get sorting.
- if possibile, wouldn’t it be more logical to select the parent to automatically include the subcats for sorting? See my explanation above.
P.S.
Theme is a joy to work with! Great job!March 25, 2019 at 1:05 am #1082432Hi,
Thanks you for sharing your solution and sorry for the delay.
1. You do not have to choose all portfolio subcategories to get sorting just hold the ctrl key and click on the required categories. I have created a test page and shared the link for in private.
2. I understand what you are saying but every user has a different requirement so I think it was a development decision to provide an option to select the categories as per user choice :)Best regards,
VinayMarch 25, 2019 at 12:32 pm #1082628Hi,
Thanks for taking the time to look at this. Unfortunately though, the test page you set up proves my point about the illogical nature of the choices exactly :-)
As you can see:
- 1. instead of just choosing the parent to get sorting, you need to choose ALL subcategories to display sorting
- 2. IF, like you did, you ALSO choose the parent category, then you get a DUPLICATE, i.e. PARENT = also ALL. In other words, ALL and PARENT are identical.
- 3. Conclusion: the PARENT needs to be excluded to get a proper sorting in the portfolio grid. This is not logical i.m.o. and this was exactly my point.
Perhaps one of the devs can explain the why and how of this arrangement?
Kind regards,
RobP.S.:
Trying to warn here also about some possible illogical behaviour with this “free to choose a combination of all subcategories from various parents”.
For exampke consider this scenario:
if you have 2 different portfolio cats, each with subcats, and both have a subcat with the exact same name, say “sour fruits”, then what would be the result in the sorting options? Would they display separately in the sorting or be merged even if belonging to different parents? Just saying.- This reply was modified 5 years, 8 months ago by rob2701. Reason: added explanation of why I'm worried about this
April 2, 2019 at 12:56 am #1085762Hi,
PARENT = also ALL. In other words, ALL and PARENT are identical.
That is not the case for every installation. Some installations are not using sub or child categories from a single parent category, some are using multiple parent categories.
if you have 2 different portfolio cats, each with subcats, and both have a subcat with the exact same name, say “sour fruits”,
Yes, both categories will display regardless of their name. The sort script relies on the category slugs, not the actual category names, so the sorting will still work.
Best regards,
IsmaelApril 2, 2019 at 7:01 am #1085870Hi Ismael,
Thanks for the clear explanation about the sorting script.
I do understand the why, i.e. giving the user freedom to select any combination of cats/subcats, but it just feels counterintuitive to me to have to exclude the parent when using subcategories :-)
It’s just something I need to add to my “that’s just the way it is” list.Kind regards,
Rob -
AuthorPosts
- The topic ‘Highlighting active parent menu item on subitem opening’ is closed to new replies.