Collapsible Menus

10/15/2005 · 7 comments

in Featured, JavaScript, XHTML

I have implemented pureDOMexplorer (pde) in the sidebar to clean up the navigation a bit. It sits upon a foundation of accessible, XHTML-compliant unordered lists and uses unobtrusive JavaScript to toggle the visibility of sub-categories. It was extremely easy to implement and saved me a ton of time. I really wasn’t looking forward to writing the script to perform this functionality. Onlinetools.org is a very handy JavaScript resource that I recommend you check out if you are developing a site.

Did you like this? Please share it:

Add to Twitter Add to Delicious Add to Facebook Add to Stumble Upon Add to Digg Add to Reddit Add to Yahoo Buzz

7 comments so far… Jump into the discussion and tell us what you think.

katja 10/22/2005 at 1:33 pm

Hi Alex,
I have been trawling the web looking for solutions to introduce collapsible navigation to my web site. I have so many categories and sub categories that its getting silly. I did follow your suggestion to see if I could get pureDOMexplorer working without success. Is there something tricky you did to get it working with Wordpress?
Any help much appreciated.
K

Reply

Alex 10/22/2005 at 1:42 pm

I didn’t do anything too tricky, though I did revert back to using some of the default code versus what I wanted to use. Specifically, I ended up applying the ID nav to the containing unordered list as I didn’t feel like messing with the JavaScript to get it to work exactly the way I like. Here is the code I am using within my WP templates, hopefully it will prove helpful:

Sidebar include file:

<div id="Navigation">
<ul id="nav">
<?php /* If this is a 404 page */ if (is_404()) { ?>
<?php /* If this is a category archive */ } elseif (is_category()) { ?>
<li><a href="/">Home</a></li>
<?php /* If this is a yearly archive */ } elseif (is_day()) { ?>
<li><a href="/">Home</a></li>
<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
<li><a href="/">Home</a></li>
<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
<li><a href="/">Home</a></li>
<?php /* If this is a monthly archive */ } elseif (is_search()) { ?>
<li><p>You have searched the <a href="<?php echo get_settings('siteurl'); ?>">
<?php echo bloginfo('name'); ?></a> weblog archives
for <strong>'<?php echo wp_specialchars($s); ?>'</strong>.
If you are unable to find anything in these search results,
you can try one of these links.</p></li>
<li><a href="/">Home</a></li>
<?php /* If this is a monthly archive */
} elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
<li><a href="/">Home</a></li>
<?php } ?>
<?php wp_list_pages('title_li=<h2>Pages</h2>' ); ?>
<?php wp_list_cats('sort_column=name&optioncount=0&hierarchical=1'); ?>
</ul>
</div>

header file

<script type="text/javascript" language="javascript" src="/includes/pde.js"></script>

Hope this helps!

Reply

Pamela 10/25/2005 at 12:03 pm

Hey Alex, I checked in on your site today after a two week vacation and was surprised by the change. The site looks GREAT! I’ll have to look further into the collapsible menus, but do you know off-hand if there’s an easy way to display an icon if the particular link does expand vs. a link that doesn’t?

Reply

Alex 10/27/2005 at 9:11 pm

Thanks Pamela! Yes, the script is set up to allow you to easily add the expanded icon – via a background image in CSS I believe. I plan to implement that when I get a chance. I still need to implement a good many design tweaks.

Reply

jktan 10/13/2006 at 2:38 am

Hi, Alex. I tried to re-create collapsible menus at my website, but to no avail. Can advise me on what went wrong please?

Reply

Alex 10/17/2006 at 9:55 pm

Hi jktan, I’d be happy to help out. Do you have a page I can look at?

Reply

fiordisale 2/5/2009 at 5:02 am

Hi, Alex. I tried to re-create collapsible menus at my website, but to no avail. Can advise me on what went wrong please?
I want to gather in different voices the different categories (example
a) archive-time with sub-category of one voce for year
example ARCHIVI MENSILI IN THE 2005-06-07-08-09 (ETC)
and it expands the months for the years

b) a separate voice for every macro category (“Che ora è”
“extra”
“Genova”
Ricette”
“lievitati”
“schiamazzi grafomani”
ec…)
Help me plis!
from Italy with love :-)

Reply

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: