Wordpress highlight current page link
What's the best way to approach this problem:
I have a list of navigation links in the sid开发者_运维知识库ebar, which must all have different, specific colours when hovered over, they are all the same colour the rest of the time. They are also nested (manually, is there an easy way to do hierarchical pages too?). The links all point to Wordpress pages. I want to be able to set the link to the current page to be permanently colourful (not just on hover).
Other than hard-coding this checking page-ids, how could I tackle this problem?
Found this helpful when I was doing it. From the Wordpress Codex.
if ( is_page('Page One') ) { $current = 'one'; } elseif ( is_page('Page Two') ) { $current = 'two'; } elseif ( is_page('Page Three') ) { $current = 'three'; } elseif ( is_page('Page Four') ) { $current = 'four'; }
Wordpress already has page identification built in. The is_page function accepts the page name as the variable. Just toss that in your id or class and you're golden.
精彩评论