highlight category links in sidebar once again
-
Hello,
I managed to display categories in sidebar with descriptions. Now I want to highlight current category name when user is on category archive or displays the post from given category. I maganed to add class to the category when user is on category archive but when he displays any posts only the first category is highlighted. My code is:<?php $argss = array( 'type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0, 'hierarchical' => 1, 'exclude' => 1, 'taxonomy' => 'category', 'pad_counts' => false ); ?> <div class="sidemenu"> <?php $categories=get_categories($argss); foreach($categories as $category) { echo '<p class=""><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . 'class="'; if(is_category || is_single()){ $cat = get_category_by_path(get_query_var('category_name'),false); $current = $cat->cat_ID; $current_name = $cat->cat_name; if ($current == $category->cat_ID) { echo 'current-category'; } else { echo $category->cat_ID; } } echo '">' . $category->name . '</a>' . '<br />' . '<span class="mendesc">' . $category->description . '</span>' . '<span style="font-size: 10px; float: right">' . ' (' . $category->count . ')</span>' . '</p>'; } ?> </div>
Thanks in advance for reply!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘highlight category links in sidebar once again’ is closed to new replies.