• I’m trying to make a Dynamic Menu so that the current category is highlighted. I’ve found this code which I’ve tried to modify, but so far it’s not working correctly. Any help appreciated!

    <ul id="nav_01">
    
    <? if(is_category() || is_single()){
     $category = end(get_the_category());
     $current =$category->cat_ID;
     $current_name = $category->cat_name;
    }
    //echo $current_name . " has id ".$current; ?>
    
    <?php if (is_category($current)) { $highlight = "current"; } else {$highlight = ""; } ?>
    <li class="<?php echo $highlight; ?>"><a href="<?php echo get_settings('home'); ?>"><?php the_category('title_li='); ?></a></li>  
    
    </ul>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The code above is adding a class called “current” under certain conditions. It is not going to make any changes to the way the category is displayed (highlighted) until you set up some CSS to do so.

    You do that in your theme’s style.css file.

    For the above, something like
    ul#nav_01 li.current { background-color: #fff; color: #FF0000; }
    which makes a white background with red text

    Thread Starter modern

    (@popart)

    I already have the CSS in place. The above code does change the current category title correctly. But it’s not listing the other categories…. What am I missing to make the other categories display normally?

    Thread Starter modern

    (@popart)

    <li class="<?php echo $highlight; ?>"><a href="<?php echo get_settings('home'); ?>">Latest News</a></li>

    The code above works correctly to highlight “Latest News”, but I’d like to replace “Latest News” with a dynamic menu so that it lists all categories and only highlights the current one…. Should be something like:

    <li class="<?php echo $highlight; ?>"><a href="<?php echo get_settings('home'); ?>"><?php wp_list_categories('orderby=name&title_li='); ?></a></li>

    but, that doesn’t work. It lists all categories but doesn’t highlight the current one.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dynamic Menus (archive categories) with current category highlighted’ is closed to new replies.