« Category Depth 0.9 | Main | Pay for Plugins »

February 08, 2005

Hierarchical Dropdown List of Category Archives

category_dropdown.gif

First, there was the monthly archive dropdown featured on Learning Movable Type. I thought it was a great idea, especially since this blog is starting to get a little long in the tooth (not that long, mind you, but long enough that listing all the archives one by one gets to be a page-design issue because of the length involved). It worked perfectly for my monthly archives, but I wanted to involve the category hierarchy I have put together for my categories in the archive list, and with the template code Elise has on her site, the hierarchy would not be reflected.

Maybe it is a point of pride for the guy that wrote the SubCategories plugin and then integrated it into the Movable Type core. Maybe I figure a flat category listing for my blog would not make any damned sense. Either way, I set out to build a dropdown that incorporated the category hierarchy.

So, with Brad's wonderful PerlScript plugin and a new one of my own creation (Category Depth), here's how I do it.

<form action="" name="pulldowncats">
<select name="pulldowncatsselect" onchange="document.location=pulldowncats.pulldowncatsselect.options[selectedIndex].value">
<option value="">Select Category</option>
<MTSubCategories>
<option value="<MTCategoryArchiveLink>">
<MTPerlScript>
print "&nbsp;&nbsp;"x"<MTCategoryDepth>"."<MTCategoryLabel>";
</MTPerlScript>
</option>
<MTSubCatsRecurse>
</MTSubCategories>
</select>
</form>

Posted by rayners at February 8, 2005 10:21 PM

Trackback Pings

TrackBack URL for this entry:
http://mt.rayners.org/mt-tb.cgi/451

Listed below are links to weblogs that reference Hierarchical Dropdown List of Category Archives :

» Hierarchical Dropdown List of Category Archives from Looking Out
He does it again He being David Raynes of MT Subcategory fame (Among other things) has gone and done it again. This time he's done a Hierarchical Dropdown List of Category Archives, something I've been missing since forever. Hopefully we'll... [Read More]

Tracked on February 9, 2005 12:33 PM

» Hierarchical Dropdown List of Category Archives from einfach-persoenlich Sideblog
David Rayner ergänzt Drop-Down-Menüs für Movable Type-Archive durch die Darstellung eingerückter Sub-Kategorien. [Read More]

Tracked on February 10, 2005 04:38 AM

Comments

Great idea David! I've linked to it from the LMT tutorial.

BTW, I've turned off the ability to allow pings from autodiscovery because of trackback spam. So, if you would like to TB to the LMT tutorial, please do, but note that you have to enter the TB URL by hand. Ugh, a pain, but oh well. Cheers to you!

Posted by: elise [TypeKey Profile Page] at February 10, 2005 03:12 AM

Hello Dave, I have been attempting to use your "category depth" plugin to produce the 'Hierarchical Drop Down' and I'll be damned, but it just doesn't work!

No errors, the <MTPerlScript> just doesn't execute. Here is the template that I am using (it needed to modified from your slightly so that it would validate as XHTML[strict]):

<div class="search-box">
 <script type="text/javascript" src="<$MTBlogURL$>quicknav.js"></script>
  <form action="" id="pulldowncats"><div>
   <label for="pulldowncats" accesskey="5"><strong>Archives:</strong></label><br />
   <select class="quickselect" name="fieldname" onchange="openDir( this.form )">
    <option value="">&nbsp;--&nbsp;Select Category&nbsp;--&nbsp;</option>
    <MTSubCategories>
    <option value="<$MTCategoryArchiveLink$>" class="gry_bck">
     <MTPerlScript>
       print "--;"x"<$MTCategoryDepth$>"."<$MTCategoryLabel$>";
     </MTPerlScript>
     </option>
    <MTSubCatsRecurse>
    </MTSubCategories>
   </select></div>
  </form>
</div>

Do you have any ideas? Thanks for all of the great plugins .. I am using several of them right now!

-Matt

Posted by: Stomper_Guy [TypeKey Profile Page] at February 22, 2005 01:26 AM

Hi its me again ... :)

I just wanted to let you know that I got it to work!
I was using your sub-categories plugin, and now that I am on MT ver 3.15 I didn't need it anymore. I removed it, finally (just been putting it off). I didn't follow your instructions for removing the sub-categories plugin, so I had some problems there, but I got it finally.

Anyway, I am happy to report that your Hierarchical Category list works now! I guess that there is a conflict between the two plugins??

Thanks again man. You are the sh&^, ok you get me! :)
-Matt V

Posted by: Stomper_Guy [TypeKey Profile Page] at February 22, 2005 07:01 PM

Way to go David . . . this will be very helpful for the site I'm developing, to organize and distinguish subcategories. However, it seems that the form code only recognizes the menu options if the particular page content on which the form code resides exists at a level where there would be at least one subcategory underneath that page.

For example, place the code on the main blog page, and the form code shows all categories and subcategories properly. However, place that same form code on an archive index page, and when you navigate to a category archive page - and that category has subcategories - all you see in the dropdown list are those particular subcategories, no categories at an equivalent or other level. If you navigate to a category archive page - and that category does NOT have subcategories, you see nothing within the dropdown list.

My problem is I want to place this dropdown list on all my pages, including archive pages, so users can go to other archive pages from wherever they are at that time.

I looked at your archive pages and didn't see the list on any of those pages, so I figured you might not have considered this issue, since the list is only residing at the main blog page level on your site.

I tried entering some absolute page pointers in the option value areas, but that didn't provide a solution. Weird thing is, I'm using Elise Bauer's month pulldown list code for monthly archives and those lists display properly on any page, so I'm assuming there's an issue either within the code particular to displaying subcategories, or there's some other fix that I'm too brain-dead to figure out.

I would appreciate it if you know what to do in this situation, or if there are any others out there who have employed David's solution who could lead me in the right direction.

Thanks!

Mark

Posted by: MadDog [TypeKey Profile Page] at May 4, 2005 04:17 PM

OK, I learn something new every day! Turns out I need to employ the MTInclude tag to reflect the fact that most Movable Type tags (as Michael Schneider points out very eloquently in his Showing recent Entries in the Sidebar discussion) "work with respect to the context in which they are used." Thus, David's instructions are as universally sound as they can be under the contraints of the program. Using the MTInclude tag as Michael suggests allows the hierarchical pulldown menu to be used on all index page levels.

Relative to Michael's instructions, here's what I did to employ David's menu style on all my pages:

1) Created a new template file Category List (categorylist.html; you could name yours whatever you want) and entered David's form code as the only element of the Template Body.

2) On the applicable index pages (all of mine for my instance - but at least Master Archive Index, Category Archive, Date-Based Archive, Individual Archive and monthly archive and weekly archive index pages if you're employing those and want this menu to show up on all your archive pages) - simple insert this tag where you want the menu to appear:

<MTInclude file="yourpath/categorylist.html">

As Michael states, the absolute path must be the path to your output directory. This is the same path that you entered as the "Local Site Path" in your weblog configuration. And remember, "categorylist.html" is what I named my index file to be "included". Yours might be named differently.

Lastly, remember to rebuild the whole site before viewing.

I hope this helps everyone who needs to employ David's terrific solution on a wider page scale similar to what I'm doing!

Thanks, Mark

Posted by: MadDog at May 9, 2005 05:24 PM

Post a comment




Remember Me?

(you may use HTML tags for style)