WordPress.org

Ready to get started?Download WordPress

Forums

How to change wp_list_pages output to my own classes? (3 posts)

  1. tracyberna
    Member
    Posted 5 years ago #

    I'm using wp_list_pages to output the nav on a blog. However, the client wants a change to the nav links that'll require me, for CSS styling purposes, to give each nav li its own class or id. I guess I could use what's generated now, but it seems really messy. I also don't want to hardcode the navs, I'd still like them to generate, but my knowledge of PHP syntax is really remedial. Basically, here's my goal -- My code now:
    <?php wp_list_pages('title_li=' ); ?>
    generates

    <li class="page_item page-item-6 current_page_item"><a href="http://mysite.com/wordpress" title="Home">Home</a></li>
    <li class="page_item page-item-8"><a href="http://mysite.com/wordpress/calendar" title="Calendar">Calendar</a></li>
    <li class="page_item page-item-250"><a href="http://mysite.com/wordpress/press" title="press">Press</a></li>

    Etc.

    What I'd like to generate is:

    <li class="home"><a href="http://mysite.com/wordpress" title="Home">Home</a></li>
    <li class="calendar"><a href="http://mysite.com/wordpress/calendar" title="Calendar">Calendar</a></li>
    <li class="press"><a href="http://mysite.com/wordpress/press" title="press">Press</a></li>

    I could also work with li IDs instead of classes. And I'd still like to use the ".current_page_item" class, so if we could keep this or find a way to generate something that'll work the same, that'd be awesome.

    Is it possible to use PHP somewhere in my header to do this?

  2. esmi
    Forum Moderator
    Posted 5 years ago #

  3. mijk
    Member
    Posted 4 years ago #

    This is your answer.

Topic Closed

This topic has been closed to new replies.

About this Topic