Frank asked: “How to dynamically highlight current page?”

Frank, a reader from UK, asked me how he can highlight the current page. When navigating throught pages, WordPress automatically add a class to the current element, so you can use css to style it as you want.

The function used to create a list of published pages, wp_list_pages(), automatically add a class current_page_item to the list item corresponding to the page you're viewing.

You just have to add the .current_page_item class to your style.css file:

/* Style the list element */
li.current_page_item{
background:#eee;
color:#777;
}

/* Style the link element */
li.current_page_item a{
text-decoration:underline;
}

9 Responses

Oct 15 2008 00:20

Thanks mate!

Oct 18 2008 23:54

I’ve always wanted to know how to do this. Thanks for the help.

Oct 30 2008 19:46

AAAH ! YES ! Thank you so much !

Oct 31 2008 01:09

Not sure why you would want to highlight a page. What would be useful, however, would be the ability to dynamically highlight the latest post. Any clues?

Nov 04 2008 02:01

Can we see a copy of the php? If the list is dynamically generated, how do we assign to actual list items?

Apr 09 2009 23:38

Thanks for this tip, i’m gonna use it for sure!

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required
Blog And Make Cash