Title: Problem in dynamic menu highlighting
Last modified: August 19, 2016

---

# Problem in dynamic menu highlighting

 *  [julious](https://wordpress.org/support/users/julious/)
 * (@julious)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/problem-in-dynamic-menu-highlighting/)
 * It’s a problem to create a dynamic menu in my blog.
    Used as a documentation:
   [http://codex.wordpress.org/Dynamic_Menu_Highlighting](http://codex.wordpress.org/Dynamic_Menu_Highlighting)
 * **My code:**
 *     ```
       <?php /* Dynamic Menu Highlighting - CSS */
       if ( is_home() ) { $current = 'home'; }
   
       elseif ( in_category(10) || in_category (11) || in_category (12) ) { $current = 'new'; }
   
       elseif ( in_category(20) || in_category (21) ) { $current = 'games'; }
   
       else { $current = 'others'; }
       ?>
       ```
   
 * The menu worked, but the problem is when I make a publication in two different
   categories parents, then if I published the same post in the category ‘games’(
   20), sub-category ‘online games’ (21) and also in the category child ‘news’ (
   12) that is within the category default (10), and when user enters the category
   games (www.myblog.com/category/games), instead of highlighting the link games,
   highlighting the link default (as if you were on (www.myblog.com/category/default).
 * I think I get it correct, is missing define any further condition in the code,
   someone could help me?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [julious](https://wordpress.org/support/users/julious/)
 * (@julious)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/problem-in-dynamic-menu-highlighting/#post-680972)
 * Is another thing that I forgot to ask been in fact a mistake of the programming
   of the code of the theme it is or if it is a bug of the wordpress?
 *  [Adam Brown](https://wordpress.org/support/users/adamrbrown/)
 * (@adamrbrown)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/problem-in-dynamic-menu-highlighting/#post-680974)
 * Whichever category gets picked up first in your if…elseif…elseif chain is the
   one that will be highlighted. This is not a bug. That’s just how PHP works.
 * If you don’t want to highlight category 10 unless category 20 is not also checked,
   then change the order of the conditions:
 *     ```
       <?php /* Dynamic Menu Highlighting - CSS */
       if ( is_home() ) { $current = 'home'; }
   
       elseif ( in_category(20) || in_category (21) ) { $current = 'games'; }
   
       elseif ( in_category(10) || in_category (11) || in_category (12) ) { $current = 'new'; }
   
       else { $current = 'others'; }
       ?>
       ```
   
 *  Thread Starter [julious](https://wordpress.org/support/users/julious/)
 * (@julious)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/problem-in-dynamic-menu-highlighting/#post-680976)
 * But the mistake inverts like this just, therefore when it is in [http://www.myblog.com/category/default](http://www.myblog.com/category/default)
   and the last post it is of the category default and game, then it will go highlight
   you game.
 * Doesn’t have as quite so to solve? Because me when I work with PHP using querry
   strings there is the definition of variables:
    In games.php: $page = “games” 
   In home.php: $page = “default”
 * In code:
    if ( $page == ‘games’ ) { echo “Games”; } elseif ( $page == ‘default’){
   echo “Home”; } else { echo “Error – No category”; }
 *  [Adam Brown](https://wordpress.org/support/users/adamrbrown/)
 * (@adamrbrown)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/problem-in-dynamic-menu-highlighting/#post-680977)
 * Apparently I’m not understanding your question.
 *  Thread Starter [julious](https://wordpress.org/support/users/julious/)
 * (@julious)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/problem-in-dynamic-menu-highlighting/#post-680978)
 * I only wanted to know if is there a way for when it is for instance in category/
   games highlight the link of the category games, even if the last post to be in
   other categories.
 * Because of the way that you suggested me, it will change the place error, when
   it is in the category default, but it will continue.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Problem in dynamic menu highlighting’ is closed to new replies.

## Tags

 * [dynamic-menu-highlighting](https://wordpress.org/support/topic-tag/dynamic-menu-highlighting/)

 * 5 replies
 * 2 participants
 * Last reply from: [julious](https://wordpress.org/support/users/julious/)
 * Last activity: [18 years, 4 months ago](https://wordpress.org/support/topic/problem-in-dynamic-menu-highlighting/#post-680978)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
