Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Dynamic menu highlighting issues WordPress

  • SOLVED

I am using dynamic menu highlighting in a menu

<li<?php if ( is_category('galleries') ) { echo ' id="current"'; } ?>><a href="/test/index.php/category/galleries/">Gallery</a></li>
<li<?php if ( is_home() || is_page('blog') || is_category() || is_single() || is_date() ) { echo ' id="current"'; } ?>><a href="/test/index.php/blog">Blog</a></li>


the problem i am running into is I want to exclude certain categories from being highlighted on certain links and am not sure how to do this. So in the above example on the 'blog' link I only want to highlight if the page is a category page but to exclude the 'galleries' category.

Also if possible I want to link in the is_single() with certain categories, so highlight this link if is_single() but to exclude it if is_single() is in a certain category x or include it if it is in catefory y

can this be done or do i need to employ a different tactic or method all together?

Answers (2)

2010-09-23

Kailey Lampert answers:

How about something like this:

<li<?php if ( is_category('galleries') ) { echo ' id="current"'; } ?>><a href="/test/index.php/category/galleries/">Gallery</a></li>

<li<?php if ( is_home() || is_page('blog') || is_category() || is_single() || is_date() ) {
if (!is_category('galleries') && !in_category('galleries')) {
echo ' id="current"'; } } ?>><a href="/test/index.php/blog">Blog</a></li>



richard o' neill comments:

nope that aint working no class being applied to the link at all now! or i being an idiot somehow, site in question is here

[[LINK href="http://golfgtisportline.com/test/index.php/blog/"]]http://golfgtisportline.com/test/index.php/blog/[[/LINK]]


richard o' neill comments:

here is my code as in your snippet,

<li<?php if ( is_category('galleries') ) { echo ' id="current"'; } ?>><a href="/test/index.php/category/galleries/">Gallery</a></li>

<li<?php if ( is_home() || is_page('blog') || is_category() || is_single() || is_date() ) { if (!is_category('galleries') && !in_category('galleries')) {echo ' id="current"'; } } ?>><a href="/test/index.php/blog">Blog</a></li>


Kailey Lampert comments:

I've attempted to replicate what you're looking for here: http://wp.trepmal.com/ ( not the 'real' navigation, but the unordered list just below)
In this example, I'm using 'uncategorized' instead of 'galleries'

If I'm on the right track, here's the code that I used:

<ul>
<li<?php if ( is_category('uncategorized') || (is_single() && in_category('uncategorized')) ) { echo ' style="background: red;"'; } ?>><a href="/category/uncategorized/">uncategorized (hightlight if is 'uncategorized')</a></li>

<li<?php if ( is_home() || is_page('blog') || is_category() || is_single() || is_date() ) {
if (!is_category('uncategorized') || (is_single() && !in_category('uncategorized')) ) { echo ' style="background: red;"'; }
} ?>><a href="/blog">Blog:: highlight if blog (main, single, archive...) - except if is 'uncategorized'</a></li>

</ul>


also note that I'm adding an in-line style instead of an id.

2010-09-24

Nilesh shiragave answers:

You have to check with is_category() for category/archive page and in_category() for single page.

for the second blog link check with in_category() and is_category()


<li<?php if ( is_category('galleries') ) { echo ' id="current"'; } ?>><a href="/test/index.php/category/galleries/">Gallery</a></li>



<li<?php if ( is_home() || is_page('blog') || is_category() || is_single() || is_date() ) {

if (!is_category('your_cat_name_as_X') && !in_category('your_cat_name_as_X')) {

echo ' id="current"'; } } ?>><a href="/test/index.php/blog">Blog</a></li>


richard o' neill comments:

see above replies, you might have a solution