Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This seems like it should be easy to do, but I've not been able to find or work out a solution.

I'm using the Starkers theme and Wordpress 3.0.4, and my site auto-generates its navigation as per normal. I would like however the navigation to only show the top level pages, i.e. not display links to any pages that are children of other pages.

This is the code I am currently using.

<?php wp_nav_menu( array( 'container' => 'nav', 'fallback_cb' => 'starkers_menu',
'theme_location' => 'primary' ) ); ?>

I would like to hide the child links programmatically, but I am prepared to use CSS if someone can instead advise how to assign specific classes to the child links.

Thanks in advance for any help.

**edit 2**

I've tracked down the actual function I am using, called starkers_menu (below). However adding depth to this, or even removing the other exclusions and just using depth doesn't work either:

function starkers_menu() {
    echo '<nav><ul>';
    wp_list_pages('depth=1&exclude=4,19&title_li=');
    echo '</ul></nav>';
}
share|improve this question
    
Where does 'fallback_cb' => 'starkers_menu' come from? I assume you use theme callled Starkers? I can't find such function or any calls to it there. –  Rarst Jan 27 '11 at 14:56
    
Yes, I'm using the Starkers theme. –  John Catterfeld Jan 27 '11 at 15:33
    
'fallback_cb' => 'starkers_menu' does not exist in the most recent version of Starkers, so can only assume you're running an older version, can you track down that function? Perhaps add a copy of the function into the question.. –  t31os Jan 27 '11 at 17:49
    
Good point t31os, I've added it now. –  John Catterfeld Jan 28 '11 at 11:10
add comment

1 Answer 1

up vote 1 down vote accepted

Had you tried depth argument (see wp_nav_menu() documentation)?

Also do I understand right that you do not setup menu manually and let theme generate it with custom callback that you have in your code?

Update

Same answer - try depth argument, only this time in wp_list_pages() call in starkers_menu() function. It should work, unless that function is never processed and not available at the time of menu running.

Do you use latest version of theme?.. If not consider updating.

share|improve this answer
    
Thanks for your reply Rarst - I have tried depth with no luck - see my edit in the question. And yes, I am using the theme's generated menu, I have not manually changed it yet. –  John Catterfeld Jan 27 '11 at 14:44
    
Right, I've just looked more closely and the problem was solved using depth. I hadn't noticed however that the page I was trying to hide had become unattached from it's parent, and hence was a top-level page. Doh! Thanks for everyone's help. –  John Catterfeld Jan 28 '11 at 11:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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