Archived topic
Category in main menu -> post count
12 replies · Started by stefan.zwahlen on August 21, 2015
Hello folks
I'm struggling a bit with the main menu! My menu contains some categories like "News" and I'd like to show the number of posts within such categories directly in the menu. Let's say the category "News" contains 8 posts, the menu should show "News (8)".
I tried different solutions including a custom walker for WP_NAV_MENU but the the mobile version of Generatepress did not work properly with this modification.
Is there a easy way to modify some source code?
Any hints or sample codes very appreciated :-)
Thanks!
Stefan
Hi Stefan,
You can try a function like this: https://gist.github.com/generatepress/050648ac7d2d566865ac
Not 100% sure it will work, but worth a try :)
Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/
Wow! That worked great.
I tried adding the code through GP Hooks but it didn't work, so I added it to functions.php in my child theme.
Thank you
Awesome! You're welcome :)
Hi Tom,
the code works great however im trying to hide the counter in the main level menu . how do i achieve this pls. css dont work as the menu class is related to the below menus.
thanks
Hi there,
I'm not sure I understand. Are you only wanting the count to show in the sub-menus?
Hi tom yes. thanks.
Can you link me to your site?
hi tom, i think its here , https://generatepress.com/forums/topic/category-tag-color/
thanks.
anyway , the snippet code seems to be crashing with toolset plugins, i need to check with them on this.
Did you remove the code for now? I'm not seeing any counts.
yes, pls look at my above reply part
the snippet code seems to be crashing with toolset plugins, i need to check with them on this.
What about it is crashing? Are you getting a specific error?
yes. ill update on this soon as it doesnt affct the site at the moment. thanks tom. !