This is like the fourth category plugin in two weeks! But as I was dinking around with the code, I finally figured out how to make the {exp:weblog:categories} tag dynamic- meaning the subcats only show when on a category page for a category that’s in the same tree. Um- here’s an example. Click a link, you’ll see what I mean. I’m using it now- so the bits I’m personally concerned with work. It replaces a seriously ugly hack I had going before.
This may or may not be useful- I haven’t looked at the other new cat plugins enough to figure out if they do exactly what I want or not. If it’s useful, let me know. If it works for folks who use category names in the url, let me know (untested- but the code is there). If it works for folks with auto_assign_parent_cats off, let me know (also an untested environment).
Needs a bit of tweaking- I’m pretty sure I’m going to remove one query. But until any debugging is finished, I’m leaving it in. I may make this thing work on individual entry pages as well- the more I think about it, the more I think it would be handy. Um- I did add parent_id as a variable, but not a conditional one. I’m debating on that- not sure I see much use in it.
Anyway- the code should be maintained, as I’m using it on my site. Whether or not I actually submit it to the plugin list depends on whether it ends up seeming redundant.
pi.dyno_cat.zip - read the plugin docs, there’s sample code. It works just like the {exp:weblog:categories}, just with a few additional parameters and variables.
Wow! Excellent work Robin. I think I may have a use for that immediately. It could replace something I have done where I’m using categories for primary navigation. It was also looking a bit ugly. We are spoilt for choice in category plugins now. I think each one brings something slightly different to the table so all could potentially be useful depending on the project..
Way cool - thanks tons for posting this.
I haven’t explored the other options in detail either, but in browsing quickly through the examples I didn’t see anything that allowed a more graceful way to use cats and sub-cats for navigation as this does, which I often have a need for in using EE to drive more traditional (non-blog) websites.
Thanks again!
This is a great plugin and is exactly what I was looking for, thanks for making it available. I’ve run into a little bug - the very last subcategory doesn’t display. I have the category group in custom order, and if I switch the order of the last two categories, whichever is last disappears.
Hm- oddness. I’ve got a hard copy I’ve been going over, trying to tighten things up- cause it’s a mess- and add support for single entry pages being ‘open’ for the cats the entry is in- because I really want that. I also suspect there are problems when cat names are used in the url, and am playing with that.
In short, hopefully I’ll have a tighter version up tomorrow and you can check if it clears up the problem.
Heh- I’ve updated that part, it was a matter of defining an array earlier in the process. But I’m wanting to get it working on single entry pages before I upload a new one. That’s mainly because I want to use it on single entry pages.
MEMEMEMEME! It’s all about ME! 😉 But if I’d stop messing around here I could have a new one up soon. Maybe tonight if I don’t go out- Sat. otherwise.
Good timing, iteria! I just uploaded a new version. (I think it should work ok with older versions of EE, though I haven’t tested it. I do recall some changes in the globals, though. So it’s possible it’s not backwards compatible. Only way to know is to test it out.)
The newer version is still a work in progress, but I did clean up an odd bug or two that could cause categories not to show when they should. I also more fully tested on an EE install using category names in the url and auto-assign cats ‘off’. This thing is a pain to test due to all of the possible permutations. However, I think I’ve covered the biggies.
A couple of new parameters were added:
-weblog_id - if you want to restrict display so that empty categories aren’t displayed AND more than one weblog uses the same category group, you can specify a specific weblog or weblogs (“1|3|4”) to base your ‘show_empty’ on.
-disable - if you aren’t using the {count} variable, you should include disable=”count” and save yourself a query.
-active_id - still experimental, it currently takes one parameter- active_id=”current”. If this parameter is set, then when on a category page, the <li> for that category will be given a css id=”active”.
-single_tree - still experimental, it currently takes one parameter- single_tree=”all”. If this parameter is set, then when on a category page ONLY the categories in that hierarchy will show (the other parent cats won’t).
The last two were added after talking to Randy about being able to show just a single hierarchy. I know he’d like to be able to not show the parent either- but that was more complicated than I initially thought it would be. Anyway, it is something I’m playing around with.
For the future, I’d still like to get this working on the single entry pages- so it can show the full hierarchy open for any cats the entry is in and only the top level cats otherwise.
I’d also like to change the way caching works- right now, it will take the regular cache parameter, as will most EE tags. However, it caches on a per page basis. Now, if you’re not using cat names in your urls, there’s no reason to do a separate query for when you’re on C1 vs C5- but right now, that’s how the cache works. I’d like to figure out a way around that.
Also- need to dink around more with giving id’s or classes to the li/ul’s. Also, the code looks like it was written by monkeys on speed and I’ve probably got more loops in there than I should. So- needs more cleaning.
If anyone spots problems or has requests/ideas, just let me know. Download replaces the one in the original post - pi.dyno_cat.zip.
Thanks Robbin! The weblog_id is a savior. The way the normal EE category function works where it shows all from every weblog is a real deal killer. Having to show the parent is problematic for me in this instance. But, thanks to you (and a couple other query kings/queens), I’ve managed to construct some queries, combine those with some {if} statements (on segments) to make it all work, and it even highlights the section/subsection/subSubsection that one is browsing without using CSS-IDs. I wouldn’t want to have to explain how I did it though :-)
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.