Erik Knutsson
Erik Knutsson

Reputation: 3

How to display pages in my way Wordpress

I have a problem with my navigation. I want to display all of my pages and theirs child pages. I want to display the child in a dropdown menu I got. In the code you can see how it works if I hardcode the meny. Now I want it to work with wp_list_pages(); so I dont haft to hardcode in for every page.

I want to display my pages like this, in my wordpress site

<div id="navigationContainer">
<ul id="navigation">

<li class="navLi">
<a href="" title="" class="navA">Start</a>
</li>

<li class="navLi dropdown">
<a href="" title="" class="navA">Page</a>
<ul>
<li><a href="" title="">Child</li>
</ul>
</li>

<li class="navLi dropdown">
<a href="" title="" class="navA">Parent</a>
<ul>
<li><a href="" title="">Child</a></li>
<li><a href="" title="">Child</a></li>
<li><a href="" title="">Child</a></li>
<li><a href="" title="">Child</a></li>
</ul>
</li>

<li class="navLi">
<a href="" title="" class="navA">Page</a>
</li>

</ul>
</div>

Thanks for now.

// Erik

Upvotes: 0

Views: 118

Answers (1)

Artur Kim
Artur Kim

Reputation: 425

You can add the dropdown class by adding the following code to your functions.php file:

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

Upvotes: 1

Related Questions