tags:

views:

30

answers:

3

Hello i am working on a menu in wordpress and made it dynamicly like this:

<?php wp_list_pages('sort_column=menu_order&depth=1&title_li=');?>

but when i look at my source i get the following:

<ul>
<li class="page_item page-item-5"><a href="http://localhost/private/Kife/?page_id=5" title="Start">Start</a></li>
<li class="page_item page-item-7"><a href="http://localhost/private/Kife/?page_id=7" title="Referenties">Referenties</a></li>
<li class="page_item page-item-9"><a href="http://localhost/private/Kife/?page_id=9" title="Over ons">Over ons</a></li>
<li class="page_item page-item-11"><a href="http://localhost/private/Kife/?page_id=11" title="Contact">Contact</a></li>
</ul>

What i would like to have is that the class names are the same as the title name? How would i do this?

+1  A: 

Well.. you're going to want to slugify the title name at the very least.. but why would you want article-specific classes anyway? That won't scale well at all! Are you going to modify your style-sheet every time you write a new article? I can almost guarantee you're taking the wrong approach if this is what you want to do.

Mark
The links are in fact to basic pages (Home, About us, Contact, etc) which by the look of their names won't change often, so scalability is not a huge problem in this case.. though I do agree, this is not the best way to handle this.
Litso
A: 

Unfortunately it's not possible using the wp_list_pages() function to add another class. You could do it afterwards using jquery, or script your own function in php that simulates wp_list_pages() the way you want it.

Do remember though that spaces in classes won't work.. you'll have to replace them with dashes or underscores (dashes are preferred, I believe)

Litso
And how would i replace the space? I have no idea where the class name comes from
vincent
The classname is generated by wordpress based on the article's number. If you create a new page the class will have page-item-12. It just counts up. Why do you need those specific classnames so badly? CSS? Because then you can just use `a[title="Over ons"]` etc. to style.
Litso
A: 

We've had to do this a couple of times. Though not pretty, its certainly not ugly. And, yes, there's a filter for that:

function my_page_css_class($class, $page) {
    if (!empty($page)) { // sanity check
        $class[] = sanitize_title($page->post_title);
    }
    return $class;
}
add_filter('page_css_class', 'my_page_css_class', 10, 2);
Gipetto