I have to assign an "active" class to my primary-level navigation made by wordpress.

Here's my HTML:

	<li><a href="/">Home</a></li>
	<?php wp_list_pages('title_li=&exclude=21'); ?>

See WP Codex for adding classes/ids for your wordpress template:

<li<?php 
if (is_home()) { 
echo " class=\"active\"";
}
?>><a href="/">Home</a></li>

WordPress instantly adds relevant classes to list out products which are made while using wordpress_list_pages() function. For instance, it'll give a class of current_page_item towards the page that you simply are presently viewing - permitting you to definitely style this specific list item in a different way.

This only works best for pages and afaik doesn't work for posts. However, there's a rather hack-ant way around it. For those who have a listing of posts out of your loop, each publish may have a category with publish-## -- where ## may be the ID from the publish (as lengthy as you apply the get_publish_class() function, or similar)

You may also obtain the ID from the current publish being displayed by:

Outdoors from the listing of posts you're outputting, ideally inside your header.php, have:

$this_posts_id = $post->ID;

Then inside from the loop from the listing of posts you're making:

if($this_posts_id == $post->ID;){echo "current";}

or something like that similar!

Hope that can help