• I want to create a dropdown menu of child pages with an indicator to the right of each page that has one or more child pages.

    I use wp_list_pages to output nested lists, is there a way to add class=”parent” to each list item that has child pages?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter kasperbs

    (@kasperbs)

    Thanks for your reply.

    I think that I might have misunderstood you, or you misunderstood me.

    What I would like to do is to add an indicator next to any menu item that might have children. Like this example here: https://www.cssplay.co.uk/menus/final_drop.html

    You will see that every menu item that has sub pages, has a little indicator next to it.

    Can I get WordPress to add the class <li class="parent"> to each
    <li> tag that is output by wp_list_pages which have sub pages?

    Thread Starter kasperbs

    (@kasperbs)

    This example might show what I want to achieve.

    This is what WordPress prints by default using wp_list_pages:

    <li class="page_item page-item-27">
      <a href="#">Parent</a>
      <ul>
        <li class="page_item page-item-33">
          <a href="#">Child And Parent</a>
          <ul>
            <li class="page_item page-item-39">
              <a href="#">Child</a>
            </li>
          </ul>
        </li>
      </ul>
    </li>

    This is what I would like WordPress to print dynamically for me:

    <li class="parent page_item page-item-27">
      <a href="#">Parent</a>
      <ul>
        <li class="parent page_item page-item-33">
          <a href="#">Child And Parent</a>
          <ul>
            <li class="page_item page-item-39">
              <a href="#">Child</a>
            </li>
          </ul>
        </li>
      </ul>
    </li>
    Thread Starter kasperbs

    (@kasperbs)

    Help…

    I needed something similar, the most simplest solution is to modify the classes.php in the wp-includes->start_el where the lists are generated. I created and additional class in the css_classes array of
    'level-'.$depth
    (depth is already declared but not used for this function) for the anchor links i added:
    class="anchor-level-'.$depth.'"
    I don’t see why this was not already done, however the modification is even more simple then the complex solutions of getting the parents then querying all the children to do this.

    Hi, Thanks Egeis your solution is working perfectly.

    Kasperbs, if you are still in an issues, this is how I solved it for class=”parent-level-$depth’:

    https://www.ads-software.com/support/topic/419199?replies=3

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding class=”parent” to parent pages automatically’ is closed to new replies.