WP nav question
- Started
- Last post
- 11 Responses
- jamble
This has me slightly stumped and the wordpress forums are shit.
Anyone know how I can modify the standard WP nav:
<?php wp_list_pages('sort_column=menu_order&title_li=&depth=2'); ?>
So that it outputs a class on any sub pages?
At the moment I get this:
<ul id="nav">
<li><ah href="#">Link</a></li>
<li><ah href="#">Link</a>
<ul>
<li><ah href="#">Link</a></li>
</ul>
</li>
<li><ah href="#">Link</a></li>
</ul>I just want to add a class of subnav to the second level ul but I'm fucked if I can find out how to do it. Any ideas folks?
Cheers,
- taxiguerrilla0
Why don't you simply handle it with css?
#nav > ul > li { /* level 1 menu definition */ }
#nav > ul >li > ul > li { /* level 2 menu definition */ }
- jamble0
Styling it isn't a problem, I need a specific subnav class in order to get some jQuery niceness working as it targets the subnav class name specifically.
- taxiguerrilla0
Ah, ok, and you can't select objects with jQuery the same way?
Anyway, I can't find it now, but there is a way to obtain the list of pages / subpages using a while {} loop. I'll make a search on my HD, if I find it I'll write you the snippet.
- taxiguerrilla0
Didn't find it on my HD, but found something that could help you:
http://stackoverflow.com/questio…
I think this way you should be able to nest 2 or more loops.
- jamble0
I'll keep looking, I'm not so hot on the jQuery either so I'm just trying to cobble something together. There must be a pretty straightforward way of doing it but WP's nav isn't the best.
- acescence0
a couple options, you can go into includes/post-template.php and edit the actual function. of course this will break if you upgrade. another option is to use a filter hook to process the output of wp_list_pages before it gets output to the template. another option is to copy the entire function and paste it in your template's functions.php file, then give it a unique name and edit the html it outputs.
- Stugoo0
if you need a hand with the jquery post up some code and what your tyring to do and ill see if i can help
- bulletfactory0
sometimes it's easier to do a hybrid of hardcode/dynamic.... example:
<?php if (is_page('About') || is_page('Contact')) { ?>
<ul class="subnav">
<li><a href="<?php echo bloginfo('url'); ?>/whatever.pdf" title="link">link</a></li>
</ul>
<?php } ?>hope that helps.... and was what you were asking.
- this would be in sidebar.php or wherever your nav sits. this entire code would also be surrounded by another list item (nested)bulletfactory
- jamble0
Cheers folks,
I can't really hardcode the nav as the pages will be updated/added to over time so the nav will grow / change a bit and I don't want the maintenence job.
@Stugoo, I might be making a total balls of a simple job but I can't for the life of me get this (http://www.noupe.com/tutorial/d... dropdown nav to work because the .subnav class in the jQuery doesn't exist when WP generates the menu in the format in my original post.
Sorry if it's not hugely clear,I'm developing locally so I don't have a link to show at the moment.
- bulletfactory0
note: i only meant to hardcode the <ul class="subnav"> and let the list items inside it be dynamic.
it could grow as large as you want and be fine.
- acescence0
if you just want to do it with jquery..
$("ul#nav ul").addClass("subnav");