Hey
I'm trying to add a class/id to each item that comes out of wp_list_pages and wp_nav_menu. I got as far as doing a preg_replace on current classes on it and thats fine I can get a class in.
My problem is that I need the new class to be a variable that gets added to after each item is outputted. So a count++ after each page item. Using a variable is fine but its a count after each one thats causing me hastle.
Essentially what I'd like to end up with is something along these lines..
<ul>
<li class="item1">List item</li>
<li class="item2">List item</li>
<li class="item3">List item</li>
<li class="item4">List item</li>
</ul>
What I've got so far in the functions file is
$idcounter = 0;
function add_markup_cat($output) { // add a class to menu-item
global $idcounter;
return preg_replace('/menu-item /', $idcounter, $output, 20);
}
add_filter('wp_nav_menu', 'add_markup_cat');
I'm thinking its something along the lines of a for each but I just can't figure it out.
The navigation code I'm using is this that I found online..
<?php
$parent_id = $post->post_parent;
$parent = get_post($parent_id);
if($parent->post_parent){
$top_level_id = $parent->post_parent;
}else if($post->post_parent){
$top_level_id = $post->post_parent;
}else{
$top_level_id = $post->ID;
}
if($parent->post_parent){
$children = wp_list_pages("title_li=&child_of=19&echo=0");
$my_id = $parent->post_parent;
}else if($post->post_parent){
$children = wp_list_pages("title_li=&child_of=19&echo=0");
$my_id = $post->post_parent;
}else{
$children = wp_list_pages("title_li=&child_of=19&echo=0");
$my_id = $post->post_parent;
}
if ($children) {
$post_id_7 = get_post($my_id);
$title = $post_id_7->ID;
?>
<ul class="twocol">
<?php echo $children; ?>
</ul>
If anyone can help at all I'd really really appreciate it! Bangin my head off the wall here!
Thanks a million for your time
leapin