Closed Thread
Dynamic menu in WordPress
Old 11-05-2009, 03:18 PM Dynamic menu in WordPress
Average Talker

Posts: 16
Name: Bob Jones
Trades: 0
I'd like my WordPress menu to highlight the category when a single post is displayed.

This example from the WordPress codex properly applies the class of "current" in category view, but does not apply the class (although it should) when switching to single-post view:

Code:
<li<?php if ( is_category('10') || in_category('10') && !is_single())
 { echo ' class="current"'; } ?>><a href="/?cat=10">My Category</a></li>
Any thoughts?

Thanks.
slobjones is offline
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 11-05-2009, 04:26 PM Re: Dynamic menu in WordPress
Mad182's Avatar
Experienced Talker

Posts: 41
Name: Madars
Location: Latvia
Trades: 0
I don't know much about wordpress, but common sense leads me to believe that "&& !is_single()" interfere with what you're trying to achieve.
__________________
There's no place like 127.0.0.1
latvian guitar chords | runescape community
Mad182 is offline
View Public Profile Visit Mad182's homepage!
 
Old 11-05-2009, 05:48 PM Re: Dynamic menu in WordPress
Average Talker

Posts: 16
Name: Bob Jones
Trades: 0
Quote:
Originally Posted by Mad182 View Post
I don't know much about wordpress, but common sense leads me to believe that "&& !is_single()" interfere with what you're trying to achieve.
The thing is, that example is derived directly from WordPress's own documentation.

To clarify, the is_single tag calls a template that displays single posts, is_category calls the template that displays category pages and in_category refers to a specific category.

So, the argument should first look to see if you're on a category page, then look to see if you're viewing a single post, then apply a class of "current" to the appropriate category.
slobjones is offline
View Public Profile
 
Old 11-06-2009, 07:43 AM Re: Dynamic menu in WordPress
Mad182's Avatar
Experienced Talker

Posts: 41
Name: Madars
Location: Latvia
Trades: 0
PHP Code:
in_category('10') && !is_single() 
It says "if in category 10 and is not single page". Try to remove "!" from is_single()...
__________________
There's no place like 127.0.0.1
latvian guitar chords | runescape community
Mad182 is offline
View Public Profile Visit Mad182's homepage!
 
Old 11-06-2009, 02:02 PM Re: Dynamic menu in WordPress
Average Talker

Posts: 16
Name: Bob Jones
Trades: 0
Quote:
Originally Posted by Mad182 View Post
PHP Code:
in_category('10') && !is_single() 
It says "if in category 10 and is not single page". Try to remove "!" from is_single()...
Mad182, thank you for your awesomeness. That did it.
slobjones is offline
View Public Profile
 
Closed Thread     « Reply to Dynamic menu in WordPress
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.12810 seconds with 13 queries