Support » Fixing WordPress » Collapsible category list?

  • Hello, seems i got little problem. Since i have over 30 categories on my site i want to use collapsible menu for them to make navigation easier. I’ll do it in a manner as descrided on Wiki ( But in that example user has to add menu items manually. Is there a way to get conetnt for menus using WordPress internal functions?

Viewing 15 replies - 1 through 15 (of 26 total)
  • Mark (podz)


    Support Maven

    This will do it to:

    <li id="categories"><?php _e('Categories:'); ?><br />
    <form action="<?php echo $PHP_SELF ?>" method="get"><br />
    <?php dropdown_cats(); ?><br />
    <input type="submit" name="submit" value="view" /><br />

    Thanks! That’s makes the look much more compact. Is there some function to implement tree-like structure? So when the user clicks on parent category links to sub-categories will appear without reoading whole page.
    Btw, what dropdown_cats() function returns?

    There are some resources out there that can produce a tree-like structure (sort of, but more like flyout menus…), but they’ll take a bit of modification of your code.
    Here’s a good one that’s xhtml compliant, accessible (508 compliant), and uses unordered lists to accomplish the feat. The problem is that you’ll need to modify your list to include the proper id and class values (as explained on their website). I haven’t tried it myself, but it shouldn’t be too difficult to get working.
    Note: don’t worry about the “Purchase” link on the site. When you go to that page, you’ll notice that it’s free for personal non-commercial use as long as you include a link-back.

    did anyone checked my link?

    Sushubh – while that code may work, it would be royal pain to integrate into a WP site.
    Depending on the particular style desired, it shouldn’t take much to create a plugin that could do the job.
    hmmm…. must think about this…. see potential in other areas, such as an archives…..

    pain? i just added a class to the UL tag and inserted a js file in the header. no hacking required. the code takes care of the lists to unlimited depth! thats the beauty of the code from a guy known as TarquinWJ from Opera Forums and accessible at the link in this thread…

    Sushubh, thanks a lot! This script was exactly what i wanted 🙂 First, i didn’t readed your link carefully enough and got how code works wrong… well, in fact i’m still not getting it fully :P… but it does what i want and it took just a couple minutes to set it up. Thanks again 🙂

    actually the link i posted was of a sister code of the code it now shows 😀
    i fixed the link a bit later :p

    I really want to use your script, Sushubh, but, remedial as I am, I cannot figure out what to do outide of inserting the javascript…and am even a bit confused as to whether I need to use the larger one (that is accessed via link, and begins with:
    var openLists = [];
    function compactMenu(oID,oAutoCol,oPlMn)
    at all or not…
    Sorry to be so dense, but can you explain a bit further?

    Great link Sushubh, I implemented the JavaScript into my wp-common.js file and made about 5 minutes worth of changes to my menu. Now all of the unordered lists collapse. Very nice.

    justkristin, you need to do 2 steps (as i remember what i did yesterday):
    1. Copy, paste and save into listCollapse.js file the script listed at the end of Then uploas .js file to you wp root folder.
    2. Put in your template after <body> tag following script:
    <script type=”text/javascript” language=”javascript1.2″ src=”listCollapse.js”></script>
    <script type=”text/javascript” language=”javascript1.2″><!–
    window.onload = function () {
    compactMenu(‘someID’,true,’± ‘);
    – you will need to replace someID tag with the correct css ID (in case of categories it should be “categories” by deflaut… i think).
    – setting second parameter in compactMenu() to true makes sub-items of menu to appear collapsed by defalult. You can set this to false if you want them to be shown on page load.

    Not quite what I am looking for, as I would prefer a non javascript solution.
    However the only way I can see it happening is if each category had a #id relevant to their ID.
    This can then be mirrored in a bit of style code in the header that sets the sub-category to display. In the main css all sub-categories would be set to display none.

    whats wrong with javascript?
    this is a code that degrades nicely in js disabled browsers… it uses dom as the author told me…
    javascript is not bad as long as it is used properly.

    A lot of the people I know actively dislike javscript. They don’t have it enabled in their browsers for this reason.
    Plus when a solution can be done in css, it is far more cross browser compatible IMO. Well that and i like css, and can code with it to get desired results 🙂 Something which i can’t do at all in javascript.
    I am slowly getting an idea of how to achieve what I want, but need to get things straight in my head first.

    elfin wrote:

    This can then be mirrored in a bit of style code in the header that sets the sub-category to display. In the main css all sub-categories would be set to display none.

    So, how would you change it to visible once the parent cat was clicked? The only way I know of is to use javascript to change the style allowing it to become visible. If there’s a “better” way, I’d like to hear/see it.

Viewing 15 replies - 1 through 15 (of 26 total)
  • The topic ‘Collapsible category list?’ is closed to new replies.