Forums

[resolved] wp_list_pages and class to <li> and <a> (4 posts)

  1. newkind
    Member
    Posted 2 years ago #

    Hi,

    If i got menu generated by wp_list_pages ie.

    <ul class="something">
        <li>
           <a href="wordpress.com/link">Text</a>
               <ul>
                    <li><a href="wordpress.com/link2">Submenu Link</a></li>
               </ul>
        </li>
    </ul>

    how can I add a class to
    <li> and <a> only where is the submenu (nested
    <ul>) ?

  2. Mark / t31os
    Moderator
    Posted 2 years ago #

    You want to add a class to the <li> and <a> elements that are produced in the output of wp_list_pages? Is that right?

  3. newkind
    Member
    Posted 2 years ago #

    yes, but only for those <li> and <a> which has another <ul> (for subpages) nested - so only those <li> and <a> that are parents

  4. Mark / t31os
    Moderator
    Posted 2 years ago #

    wp_list_pages already assigns classes..

    If you want to style them differently just use the classes..
    Top level..
    ul li.page-item {}
    child level lists..

    ul li.page-item ul {}
    ul li.page-item ul li.page-item {}

    child child..

    ul li.page-item ul li.page-item ul {}
    ul li.page-item ul li.page-item ul li.page-item {}

    and so on...

    You'll need some heavy regex to do it otherwise.. I'm not quite that hot with regex, else i'd write you something..

Topic Closed

This topic has been closed to new replies.

About this Topic