0

In relation to question posted here, is it possible to have an output to have something like this instead? where class="parent" is applied to the hyperlink?

<ul>
    <li><a href="#">Page 1</a></li>
    <li><a class="parent" href="#">Page with Subpages</a>
        <ul class="children">
            <li><a class="parent" href="#">Page with another subpage</a>
                <ul class="children">
                    <li><a href="#">subsubpage</a></li>
                </ul>
            </li>
        </ul>
    </li>
    <li><a href="#">Page 3</a></li>
    <li><a href="#">Page 4</a></li>
</ul>

the function below of TheDeadMedic works well for lists:

function add_parent_class( $css_class, $page, $depth, $args )
{
    if ( ! empty( $args['has_children'] ) )
        $css_class[] = 'parent';
    return $css_class;
}
add_filter( 'page_css_class', 'add_parent_class', 10, 4 );

is it possible to use a similar function to target hyperlinks instead of the lists?

1 Answer 1

0

According to this thread, you can add a custom Walker class to your wp_list_pages() call. It looks like that's the way to go, since wp_list_pages() prints or returns a string.

If you set $args['echo'] to false, you can do some string manipulation before you echo() it, but it seems to me that the Walker solution is probably the way to go.

Unfortunately the Walker documentation looks a little thin.

2
  • thanks, pat. it sure is hard with very little documentation /reference around. i will give the walker approach a try.
    – Pabile
    Commented Mar 13, 2013 at 7:38
  • Here's a Walker documentation page with a bit more content: codex.wordpress.org/Function_Reference/Walker_Class . Good luck!
    – Pat J
    Commented Mar 13, 2013 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.