Here it is. Download one of the following files, unpack it, and place sub_cats.pl in your plugins/ directory and mt-sc.cgi in your base MT directory. mt-sc.cgi will probably need to be chmod'ed to 755 so it can be executed.
It provides the following tags:
- MTSubCategories: a MTCategories replacement that handles the sub-categories you define
- MTSubCatIsFirst: True if this is the first category in the current context
- MTSubCatIsLast: True if this is the last category in the current context
- MTSubCatsRecurse: use the current MTSubCategories container on the next lower level of categories (i.e. the sub-categories of the current category)
- MTParentCategories: a container tag that starts with the top-most parent of the category and loops its way down
- glue: the text to use to tie the list together
- MTEntriesWithSubCategories: replacement for MTEntries that handles sub-categories
- category: if the defined, it will select entries either in that category or in any of its sub-categories
- any other arguments act exactly like MTEntries
Here are some usage examples that I've been using on my site:
Category List
<MTSubCategories>
<MTSubCatIsFirst><ul></MTSubCatIsFirst>
<li>
<MTCategoryLabel>
<MTSubCatsRecurse>
</li>
<MTSubCatIsLast></ul></MTSubCatIsLast>
</MTSubCategories>
Category Archive File Name (e.g. category/sub-category/sub-category/index.php)
archives/<MTParentCategories glue="/"><MTCategoryLabel
dirify="1"></MTParentCategories>/index.php
Category Breadcrumbs for an Entry
<MTEntryCategories glue=", ">
<MTParentCategories glue = "-> ">
<a href="<$MTCategoryArchiveLink$>"
title="<$MTCategoryDescription$>"><$MTCategoryLabel$></a>
</MTParentCategories>
</MTEntryCategories>
I also replaced all the MTEntries containers in my Category Archive Template with MTEntriesWithSubCategores to include all the sub-categories for the given category. You can also use the category list example in your Category Archive Template to produce a list of sub-categories.
To define how your categories relate to each other, just load up mt-sc.cgi in your web browser. With the dinky little interface I threw together, you can define the category -> sub-category relationship for your categories. The code will make sure that you do not define a category to be a sub-category of itself, but there are currently no safeguards against creating a sub-category loop (e.g. A is a sub-category of B which is a sub-category of A). If one of those is created, MT may get stuck in an infinite loop during your rebuilds (and therefore fail when the usual CGI timeout is hit).
Hopefully some (maye even most?) of that made sense. If you do not understand any part of this, please let me know and I will try and explain things more thoroughly.
( Note: This requires MT 2.6 or higher, and uses MT::PluginData, so the Storable perl module must be installed by your host )
Update: (2003-09-24 06:54)
I have added in some extra functionality to mt-sc.cgi thanks to Jay. Now it will print out a quick category heirarchy while you are editing. I still need to implement some kind of loop checking though. Anyways, enjoy!
template_tags=MTSubCategories,MTSubCatIsFirst,MTSubCatIsLast,MTSubCatsRecurse,MTParentCategories,MTEntriesWithSubCategories
This is really great! Thank you for writing this plugin.
Excuse the newbie question, but how do I turn the subcategory titles into links to each category?
oh, never mind, I figured it out, I think!
http://thedesignspace.net/MT2blog/
This plugin will be much applauded. It has been requested so much. I have a question though. With this one and the plugin manager, is there any way of somehow extending the mt menu to have better access to these extra pages? Possibly somehow it can check to see if these extras exist and then include them in the menu. I know I can't create it, but maybe someone out there can.
how does one delete a subcategory relationship?
*tips* support for wildcards / function/attribute to specify to show only subcategories from one category.
I have the same question as Paul: How do you delete a subcategory relationship? It looks like they're preserved even if you delete the categories involved. Or does it not make any difference? In other words, if I recreate a category I deleted in the past, will SubCategories overwrite the old info and start from scratch again?
Thanks for the great plugin!
If you're using MySQL and you're somewhat MySQL-savvy, you can delete the appropriate row from the mt_plugininfo table.
The syntax to SELECT the proper row is:
I won't list the DELETE syntax here for fear of collecting blame for data loss, but it's very similar. :)
Er, my last comment assumes that you are looking for category '25'. The 'plugindata_key' in this table is always the child category id.
David, this is absolutely wonderful.... But, of course, I have a problem.
I have a file archive template (for individual archives) like so:
<MTParentCategories glue="/"><MTCategoryLabel dirify="1"></MTParentCategories>/<$MTEntryTitle dirify="1"$>
I have gone through and created a number of primary->secondary category relationships and each of my entries has a primary and secondary category consistent with these.
However, the generated file path only includes the primary category. To debug the problem, I pasted the file archive template code into the template itself and the output confirms that the secondary category is not being printed.
I checked the mt_plugindata table and there is indeed data which correlates to the relationships I set up.
Any clues as to what might be wrong?
Ah-ha! I figured it out... I've been hacking categoy/subcategory for so long using primary and secondary categories in MT that I completely missed it...
For those who have this problem, you only set the FINAL category in the hierarchy as the main category. Assuming you have set up your relationships using mt-sc.cgi, the plugin does the rest.
Whew... Beautiful job, David.
Unless I am going about it wrong way, I am lacking an option to supress printing of the last category in a parent category recursion. I came across this problem when doing a breadcrumb for a category archive index. I wanted to style the last element (i.e. the current category) differently than the rest (i.e. no link, plain text). So what I did was print the entire recursion into a PHP array PLUS the current category unlinked. Then, I removed the second to last element of the array which was the linked version of the current category.
Also with David's help, I figured out how to print the list of entries in the current category (obvious) followed by entries in each of the recursive subcategories (not so obvious).
You can see that code, plus some others here. I would have posted it all here, but posting code in comments is ugly because of linebreaks and sanitizing...
Requested features:
* Use of selected="selected" in drop down form for last selected items. When setting up many subcategory relationships, having to reset the drop down to the category I am in is a real time waster.
* A very simple category/subcategory tree displayed below the dropdowns
David, I found a bug.
If you set up a child relationship, and then later delete the child category, you get the following error upon rebuild:
Can't call method "label" without a package or object reference at /path/to/sub_cats.pl line 46.
The relationship should either be deleted upon deletion of the child (hard, I know), or ignored by sub_cats.pl.
I haven't tested what happens if you delete the parent category, but it can't be good...
This may be a silly-ass question, but here goes:
I have a site I'm developing that will have a Publications section. That section has different TYPES of publications (articles, e-books, etc.) with a specific set of CATEGORIES spanning all Types.
What I'd like to be able to do is have one blog for the Publications section, allowing me to have display pages for each TYPE, but then allow users to navigate by CATEGORY, with each category page listing excerpts from each TYPE of publication that fits that category.
Now, if I have 6 TYPES of publications, is it possible to use MTSubCategories to map those types as parents to (say) 20 different SubCategories -- with all the SubCategories being REPEATED for each TYPE (Parent)?
Thanks!
Another newbie's question. I got an error
like this:
-Can't call method "id" without a package or object reference at /***/plugins/sub_cats.pl line 191.
Maybe I did it the wrong way, but I can't find out what's the problem.
I'll echo Jay's request for a way to organize this with a drop-down menu.
I'm sorry if this is a stupid question... Is it possible to have a list of JUST parent categories?
Nicole, the update that David just posted does all of that. I essentially satisfied both of my requests above and sent him the code...
Glassyocean, see my comment a few above yours. Is it possible that you created a parent/child relationship and then deleted one of the categories involved?
Anthony, sorry I havent gotten back to you about that one. Ive been in crisis mode recently (http://www.jayallen.org/journey/2003/09/mac_os_x_deleted_utilities_folder). Unfortunately, I dont know the answer to your question. I have one place in my current project where I would like to do the same thing, but haven't looked into using this plugin for it. I will reply via email about how I am currently doing it, once things settle down...
Thanks for your response Jay.
Well, I didn't do that but actually deleted an _entry_of a child category, so I suspect that's the cause. but don't know how I could make up for it...
Jay, I really don't know how to do the dropdowns in a way that makes it clear which is the parent category, and which is the child category. Also, I don't know how to create a dropdown list of JUST the parent categories.
Glassyocean, deleting an entry that has a category (parent or child) shouldn't throw that error. Maybe David can shed some light on this.
Nicole, I don't understand. The left dropdown is always the parent and the right dropdown is always the child. If you have the latest mt-sc.cgi, then a parent-child tree will be shown below thee dropdowns. (Or at least that was the code I sent to David)
Oh. My bad. I was talking about the dropdown menu on my own site, not the one on mt-sc.cgi. I guess what I REALLY wanted to say was: Can I create a list of just the parent categories on my own site.
Sorry if that wasn't clear before.
Nicole, take a look at David's template code for Category List above. Remove <MTSubCatsRecurse>. That should give you just parent categories...
I might be missing the obvious...
How to print out the list of sub-categories of particular parent category?
Hey all,
I'm going to reiterate Phillip Winn's post of 9/5. You have to go into your mt_plugins table to delete a subcategory once you get past a certain point.. I don't know- -maybe after it has an entry in it? Anyway, it worked for me, so Jay Allen and everyone else, give it a try-- you need to the the cat id # of the cat you're deleting, but you can get that from the mt_categories table.
ALSO-- another thing to try that seems to have worked BEFORE you place an entry in a subcategory is to simply recreate the relationship.. this seems to have the effect of deletion. So if you have A -> B and you want to delete the relationship, simply choose A -> B again in the utility, and apply the change. that MIGHT delete the relationship. But to be bulletproof, edit the DB as Phillip says here:
If you're using MySQL and you're somewhat MySQL-savvy, you can delete the appropriate row from the mt_plugininfo table.
The syntax to SELECT the proper row is:
SELECT * FROM mt_plugindata WHERE plugindata_plugin='SubCategories' AND plugindata_key='25'
I won't list the DELETE syntax here for fear of collecting blame for data loss, but it's very similar. :)
Posted by: Phillip Winn on September 5, 2003 06:42 PM
pavo33: you know the name of the category you are deleting
pattijblue: yea
pavo33: so you go to mt_category table and find the category_id # for that name
pavo33: then you go to mt_plugin and delete the row that has that same # in the plugindata_key field
pattijblue: ok
pavo33: so that cat was #290
pavo33: so then i just deleted #290 from mt_plugindata and it went away
Say I have Category A with two subcategories B and C, which are not mutually exclusive.
If I set a post to be in both categories B and C, is there any way I can get the breadcrumb trail for the entry to display something like:
Posted in A --> B, C
At the moment, the example code above ["Category Breadcrumbs for an Entry"] results in:
Posted in A --> B, A --> C.
Does anyone have any ideas?
ok, I have struggled and struggled with this all day, and for the most part got it working really well. So great big thanks for a wonderful and functional plugin.
There are just a few things that I can't manage to make work, and it could very well be a case of complete porrige brain syndrome.
I have several levels of subcategories, and I want to put breadcrumb links on each category page so you can go back a level each time. I can't get this to work at all.
Here is the first page in a series of subcategories: http://ezdesign.spayce.com/archives/design/
Also, the breadcrumbs on the entry page does work - but some entries are in more than one category. Can I ensure that only the primary category is used in the breadcrumb links?
For example on this page: http://ezdesign.spayce.com/archives/design/themes/colours_textures_and_patterns/red/000115.shtml
I don't want akabitsy's themes or hosted themes to appear in the you are here area, but I do want the entry to also be in those categories.
ok, I mananged to de-php Jay Allens' category breadcrumbs, and it works fine on all but one level of page - which I am totally stumped about!
The code is
You are here: "> | " title="">/MTEntries
Is is possible to have the primary category as a heading, and all the sub categories as links? If it is how do I go about doing that?
I'm getting this error message when I try to post: "Can't call method "label" on an undefined value at plugins/sub_cats.pl line 45."
I don't recall deleting a category, but it's possible. Sadly, I have zero understanding of MYSQL and could not follow the directions above. Should I just delete the whole plugin and forget about it?
This problem probably has nothing to do with your plugin, but here goes. When trying to execute mt-sc.cgi, I keep getting:
--clip--
An error occurred:
Loading template 'login.tmpl' failed: HTML::Template->new() : Cannot open included file /home/jn/public_html/mt/tmpl/login.tmpl : file not found. at /home/jn/public_html/mt/extlib/HTML/Template.pm line 1500
HTML::Template::_init_template('HTML::Template=HASH(0x84474b0)') called at /home/jn/public_html/mt/extlib/HTML/Template.pm line 1105
HTML::Template::_init('HTML::Template=HASH(0x84474b0)') called at /home/jn/public_html/mt/extlib/HTML/Template.pm line 999
HTML::Template::new('HTML::Template', 'filename', '/home/jn/public_html/mt/tmpl/login.tmpl', 'path', 'ARRAY(0x84a7bec)', 'die_on_bad_params', 0, 'global_vars', ...) called at /home/jn/public_html/mt/extlib/HTML/Template.pm line 1049
HTML::Template::new_file('HTML::Template', '/home/jn/public_html/mt/tmpl/login.tmpl', 'path', 'ARRAY(0x84a7bec)', 'die_on_bad_params', 0, 'global_vars', 1) called at /home/jn/public_html/mt/lib/MT/App.pm line 302
eval {...} called at /home/jn/public_html/mt/lib/MT/App.pm line 301
MT::App::load_tmpl('MTApp::SubCats=HASH(0x8102ea8)', 'login.tmpl') called at /home/jn/public_html/mt/lib/MT/App.pm line 334
MT::App::build_page('MTApp::SubCats=HASH(0x8102ea8)', 'login.tmpl', 'HASH(0x84a7b5c)') called at /home/jn/public_html/mt/lib/MT/App.pm line 241
eval {...} called at /home/jn/public_html/mt/lib/MT/App.pm line 203
MT::App::run('MTApp::SubCats=HASH(0x8102ea8)') called at /home/jn/public_html/mt/mt-sc.cgi line 179
eval {...} called at /home/jn/public_html/mt/mt-sc.cgi line 174
--clip--
Now, when I add "cms" to the default TemplatePath (in mt.cfg), the login screen appears - but, of course, when trying to login usually with mt.cgi, the path settings is incorrect. I'm using an external Template.pm (extlib/HTML) and this happens with both Movable Type versions 2.64 and 2.65, which I use.
So it seems that the part "cms" should be applied to some place?
I am attempting to implement this very useful plugin, but there seems to be a disconnect between how I think it works and how it actually seems to work.
For example, if I have this category chain: TV->Networks->ABC.
If I post an entry to the ABC category, shouldn't Networks and TV be built also to include the children categories?
The only way I can get this to happen is to assign Networks and TV as secondary categories. Doing that, however, seems to defeat the purpose of this plugin. The only thing I seem to gain is a nicely organized path (/archives/tv/networks/abc/).
Can someone confirm that I am understanding the proper usage or correct whatever I am doing wrong?
Thanks
Jol,
I'm trying to do the same thing... somewhere in MT's code there is a part that doesn't rebuild an empty category page (which makes sense if they aren't a hierarchy, because an page for a category with no entries is kinda useless in that case). I just need to find it and change it. When I do, I'll contact you.
I just wonder if there's also a way to assign a specific entry to multiple categories (but without it being the secondary category), so I can have an entry exists within two or more categories?
I'm using MT 2.64 and this is what I got when i run mt-sc.cgi. Of course, i chmoded to 755 my cgi file which is in mt folder and i put the sub_cats.pl in plugins directory:
Loading template 'login.tmpl' failed: HTML::Template->new() : Cannot open included file tmpl/login.tmpl : file not found. at extlib/HTML/Template.pm line 1500
HTML::Template::_init_template('HTML::Template=HASH(0x84428e0)') called at extlib/HTML/Template.pm line 1105
HTML::Template::_init('HTML::Template=HASH(0x84428e0)') called at extlib/HTML/Template.pm line 999
HTML::Template::new('HTML::Template', 'filename', 'tmpl/login.tmpl', 'path', 'ARRAY(0x843ff70)', 'die_on_bad_params', 0, 'global_vars', ...) called at extlib/HTML/Template.pm line 1049
HTML::Template::new_file('HTML::Template', 'tmpl/login.tmpl', 'path', 'ARRAY(0x843ff70)', 'die_on_bad_params', 0, 'global_vars', 1) called at lib/MT/App.pm line 302
eval {...} called at lib/MT/App.pm line 301
MT::App::load_tmpl('MTApp::SubCats=HASH(0x8237048)', 'login.tmpl') called at lib/MT/App.pm line 334
MT::App::build_page('MTApp::SubCats=HASH(0x8237048)', 'login.tmpl', 'HASH(0x843fef8)') called at lib/MT/App.pm line 241
eval {...} called at lib/MT/App.pm line 203
MT::App::run('MTApp::SubCats=HASH(0x8237048)') called at mt-sc.cgi line 179
eval {...} called at mt-sc.cgi line 174
Anyone has any idea?
Thanks in advance.
Liva
To fix this problem, add this line after line 27 in the file mt-sc.cgi (I guess it would work as long you put that in "sub init" but this works as a fix for me):
$app->{template_dir} = 'plugins';
this will point the template to the correct path, and fix the error that both I and others have.
There's another thing that I'd like know about though... is it possible (or at least how) to limit the category listings base on the authors' permission and such (e.g. list only blogs they have access to/list only if they have permission to modifiy category settings). I don't know any cgi so I have no idea to go about doing this... can anyone help?
ranimboy
after spending enough time on it, I have modified/extended the sub categories extension which David Raynes did, I am not sure how efficient it is but here's some features/update on it.
1. permission required (category editing) for each blog.
2. multiple blogs listing allowed (with separate interface instead of one drop down box)
3. login problem fixed (would have to login before accessing the page before, now you can just go to the page and login screen will come up)
4. hierarchical structure output instead of the original simple parent child relation output
5. disallow circular assignment of parent and child
feel free to dl this on my site.
http://rs234.dyndns.org/
And again thanks David Raynes for making such a nice script, otherwise I'd have no idea how to do this from scratch
Just a semi-random question: why isn't this listed at mt-plugins?
I think this is EXACTLY what I've been looking for, and I am so glad I stumbled across it!
I am loving this plugin! I do have one question (of course):
I am using the breadcrumb technique for individual archive pages, and have entires that fall into multiple categories. I would like for the breadcrumbs to show only the primary category. Currently the primary category shows followed by "," then the complete breadcrumb path for any secondary categories assigned to the entry. Anyone know of a way to pull this off?
oh,no,god save me~
this plugin is just what i needed.but this is the first time for me to config plugin. i feel i am so stupid..i can't know how to config it...
how to paste the code,and where on earth they should be placed?
should the code of Category List be added in the template named Category Archive?
so do Category Archive File Name and Category Breadcrumbs for an Entry?
i tried like that,but i failed..
May u help me?
Great plugin, but I have been trying for hours to get the files into the subfolders.
I have the directory structure I wanted for categories ie: mysite.com/webdesign/design/index.html
But individual entries still go into the first directory not the second.