Child category is set current-cat on parent page <p>I have parent categories which have childs. I'm listing child categories on parent category page.</p> <p><strong>I'm using archive.php template.</strong></p> <p>Now I'm facing issue with <code>current-cat</code> class on parent category page. Seems that my first child category is getting <code>current-cat</code> class when on parent category page. This <code>current-cat</code> class should be on only when on current category page.</p> <p>For example my parent category is <strong>Fruits</strong>. And when I'm on <strong>Fruits</strong> (category/fruits) page I can see child categories <strong>Apple</strong>, <strong>Orange</strong>, <strong>Banana</strong>. Problem is that <strong>Apple</strong> is getting <code>current-cat</code> class on <strong>Fruits</strong> page.</p> <p>It should get that class only when on <strong>Apple</strong> page (category/fruits/apple).</p> <p>Here is my current code:</p> <pre><code>global $wp_query; $ID = $wp_query-&gt;posts[0]-&gt;ID; $postcat = get_the_category($ID); $cat = $postcat[0]-&gt;cat_ID; $thiscat = get_category ($cat); $parent = $thiscat-&gt;category_parent; if ($parent == 0) { } else { $subcategories = get_categories('child_of='.$parent); $items=''; foreach($subcategories as $subcat) { if($thiscat-&gt;term_id == $subcat-&gt;term_id) $current = ' current-cat'; else $current = ''; $items .= ' &lt;li class="cat-item cat-item-'.$subcat-&gt;term_id.$current.'"&gt; &lt;a href="'.get_category_link( $subcat-&gt;term_id ).'" title="'.$subcat-&gt;description.'"&gt;'.$subcat-&gt;name.' &lt;/a&gt; &lt;/li&gt;'; } echo "&lt;ul&gt;$items&lt;/ul&gt;"; } ?&gt; </code></pre> <p>How to fix my code?</p>