Support » Themes and Templates » Single.php Active Category Class

  • Currently by default (I believe) when you’re on single.php, WordPress doesn’t add a “Active” class to the blog category you’re viewing the single post in like it would for pages or if you’re on the category archive. Archive also doesn’t have this (if you list them). Is there a way to add an “Active” class to posts parent categories after you list them?

    I’m listing my Categories and Archives the standard way:

    <div class="menu-item">
            <h4 class="title"><a href="<?php echo get_permalink(15); ?>">Categories</a></h4>
            <ul>
                <?php
                    wp_list_categories(array(
                        'title_li'  =>  '',
                        'echo'      =>  1
                    ));
    
                ?>
            </ul>
        </div>
        <div class="menu-item">
            <h4 class="title"><a href="<?php echo get_permalink(15); ?>">Archives</a></h4>
            <ul>
                <?php wp_get_archives('type=monthly&limit=12'); ?>
            </ul>
        </div>

    Just to clarify; When you’re on the category it will add the class current-cat to the list item, but when you’re on one of the single posts it doesn’t add any kind of class to the category to signify that the post belongs to it.

    This is the permalink structure I’m using (if it matters):

    /blog/%year%/%monthnum%/%day%/%postname%/

  • The topic ‘Single.php Active Category Class’ is closed to new replies.