Dynamic Menu Highlighting Problem
-
Hello,
I used the second method shown in Dynamic Menu Highlighting to have the navigation menu dynamically highlights the currently displayed page.
This is what I have in my header.php:
<ul id="menu"> <!-- To show "current" for Index --> <li<?php if (is_home()) { echo " id=\"current\""; }?>> <a href="<?php bloginfo('url') ?>">Everything</a> </li> <!-- To show "current" for Category --> <li<?php if (is_category('Painting') || in_category('9') && !is_single()) { echo " id=\"current\""; }?>> <a href="<?php bloginfo('url') ?>/category/painting">Painting</a> </li> <li<?php if (is_category('Illustration') || in_category('32') && !is_single()) { echo " id=\"current\""; }?>> <a href="<?php bloginfo('url') ?>/category/illustration">Illustration</a> </li> <li<?php if (is_category('Design') || in_category('25') && !is_single()) { echo " id=\"current\""; }?>> <a href="<?php bloginfo('url') ?>/category/design">Design</a> </li> <li<?php if (is_category('Photography') || in_category('55') && !is_single()) { echo " id=\"current\""; }?>> <a href="<?php bloginfo('url') ?>/category/photography">Photography</a> </li> <li<?php if (is_category('News') || in_category('51') && !is_single()) { echo " id=\"current\""; }?>> <a href="<?php bloginfo('url') ?>/category/news">About</a> </li> <!-- To show "current" for Page --> <li<?php if (is_page('Correspondance')) { echo " id=\"current\""; }?>> <a href="<?php bloginfo('url') ?>/correspondance">Correspondance</a> </li> </ul>This is what I have is my css:
#current a { color: #5c9eb8; }The result is that the navigation menu dynamically highlights the currently displayed page. All is working well except for a few issues.
When I click Everything (which is the home page), it highlights Everything & Illustration. I’m only having this issue with home. Why is this happening?
And is there a way to highlight a category when visiting a post (single page)?
Thank you!
Antonella
-
try and change these sections:
in_category('9') && !is_single()to:
in_category('9') && is_single()Alchymyth, you’ve just answered both of my questions. It’s works! You’re a genius. Thank you!!
The topic ‘Dynamic Menu Highlighting Problem’ is closed to new replies.