• How can i highlight the post’s current category in the sidebar category list when i’m on a single post? It’s highlighted for the category archive

    li.current-cat a {
    font-weight:bold;
    }

    but it doesn’t work for a single post.

Viewing 1 replies (of 1 total)
  • Thread Starter crowd

    (@crowd)

    function sgr_show_current_cat_on_single($output) {
    global $post;
    if( is_single() ) {
    $categories = wp_get_post_categories($post->ID);
    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');
Viewing 1 replies (of 1 total)
  • The topic ‘Highlight current category in sidebar for a single post’ is closed to new replies.