Comments on: Dynamic category menu highlighting for single posts http://www.studiograsshopper.ch/code-snippets/dynamic-category-menu-highlighting-for-single-posts/ Sun, 22 Mar 2015 14:44:25 +0000 hourly 1 http://wordpress.org/?v=4.1.1 By: Ade http://www.studiograsshopper.ch/code-snippets/dynamic-category-menu-highlighting-for-single-posts/#comment-237573 Fri, 19 Apr 2013 16:35:17 +0000 http://www.studiograsshopper.ch/?p=2204#comment-237573 Hi,

Frankly, no idea, I’ve never used that plugin.

Have you tried asking the plugin author?

]]>
By: Marcelo http://www.studiograsshopper.ch/code-snippets/dynamic-category-menu-highlighting-for-single-posts/#comment-237565 Thu, 18 Apr 2013 21:06:53 +0000 http://www.studiograsshopper.ch/?p=2204#comment-237565 Hi.

I´m using the plugin here mentioned ‘http://kahi.cz/wordpress/highlight-used-categories-plugin/’.

My main categories are disposed by ‘male’, ‘female’, and ‘children’.
The subcategories are the same for each of the 3 main categories.

So, the problem I found with the plugin, is that it adds ‘used-cat’ on every ‘acessories’ subcategory it finds.
Regardless of the main category in use.

It adds ‘used-cat’ on ‘acessories’ of ‘female’ main category, and it adds ‘used-cat’ on ‘acessories’ of ‘children’ main category.

I would like the code of the plugin to add ‘used-cat’, only to the sub-category of the main category in use, in the current post.

You can check it out here.

The website is in portuguese so ‘male’ means “Masculino”, “female” means “Feminino”, and “Acessories” means “Acessórios”.

Any idea what modification in the plugin code should I make?

]]>
By: Hannes http://www.studiograsshopper.ch/code-snippets/dynamic-category-menu-highlighting-for-single-posts/#comment-237417 Sun, 31 Mar 2013 21:41:15 +0000 http://www.studiograsshopper.ch/?p=2204#comment-237417 Did a similar stuff with the WP Walker class:
https://github.com/hkirsman/category_aware_walker_nav_menu

]]>
By: Don http://www.studiograsshopper.ch/code-snippets/dynamic-category-menu-highlighting-for-single-posts/#comment-140448 Mon, 15 Oct 2012 17:52:28 +0000 http://www.studiograsshopper.ch/?p=2204#comment-140448 Hi there,

I am wondering if there is a way to also add a class for current-cat-parent when inside a child post?

Thanks,

]]>
By: Arvid Eriksson http://www.studiograsshopper.ch/code-snippets/dynamic-category-menu-highlighting-for-single-posts/#comment-40341 Fri, 16 Dec 2011 04:35:32 +0000 http://www.studiograsshopper.ch/?p=2204#comment-40341 Amazing. It works very well with my custom taxonomies! The name of my taxonomy is directors_name so this is what I put in my functions.php

function sgr_show_current_cat_on_single($output) {
global $post;
if( is_single() ) {
$taxonomy = 'directors_name';
$categories = wp_get_object_terms( $post->ID, $taxonomy );

foreach( $categories as $catid ) {
$cat = get_category($catid);
// Find cat-item-ID in the string
if(preg_match('#cat-item-' . $cat->cat_ID . '#', $output)) {
$output = str_replace('cat-item-'.$cat->cat_ID, 'cat-item-'.$cat->cat_ID . ' current-cat', $output);
}
}
}
return $output;
}

add_filter('wp_list_categories', 'sgr_show_current_cat_on_single');

And this is what I put in my single.php

Thank you for your help!
/ A

]]>
By: Hansen http://www.studiograsshopper.ch/code-snippets/dynamic-category-menu-highlighting-for-single-posts/#comment-34922 Thu, 22 Sep 2011 08:15:12 +0000 http://www.studiograsshopper.ch/?p=2204#comment-34922 Thank you very much. It works ad hoc.

]]>
By: Ade http://www.studiograsshopper.ch/code-snippets/dynamic-category-menu-highlighting-for-single-posts/#comment-26361 Sun, 13 Mar 2011 07:26:26 +0000 http://www.studiograsshopper.ch/?p=2204#comment-26361 Daniel,

You are quite right – the new Custom Menu functionality makes all of this so much easier. Generally, I always recommend clients to use this rather than the “traditional” method of wp_list_categories etc.

Glad you found the article useful.

]]>
By: Daniel http://www.studiograsshopper.ch/code-snippets/dynamic-category-menu-highlighting-for-single-posts/#comment-26111 Wed, 09 Mar 2011 09:16:02 +0000 http://www.studiograsshopper.ch/?p=2204#comment-26111 Fantastic post, and great comments too – reading it pointed me in the direction of using wp_nav_menu instead of wp_list_pages or wp_list_categories

It makes everything so easy – adding classes for the first and last list item, setting up the order of list items and also styling the parent menu item if the current page is a sub page, as discussed above

If you haven’t already, do check out Justin Tadlock’s excellent walk-through of wp_nav_menu here –

http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus

]]>
By: Angelo http://www.studiograsshopper.ch/code-snippets/dynamic-category-menu-highlighting-for-single-posts/#comment-26028 Mon, 07 Mar 2011 19:26:41 +0000 http://www.studiograsshopper.ch/?p=2204#comment-26028 Yes….can you see the solution?…If there is I not understand it. Can you explain me, please?

I need the php code to assign current class to main categories.

Thanks

]]>
By: Ade http://www.studiograsshopper.ch/code-snippets/dynamic-category-menu-highlighting-for-single-posts/#comment-26020 Mon, 07 Mar 2011 18:00:26 +0000 http://www.studiograsshopper.ch/?p=2204#comment-26020 Angelo,

I think this is discussed elsewhere in the comments.

]]>