Multiple Categories and Hierarchies
After a lot of requests, its finally here. This hack will give you a more powerful listing whilst assigning multiple categories to an entry that includes the category hierarchies. As usual open up lib/MT/App/CMS.pm and around line 2772 find
$cats{ $cat->id } = $cat->label;
(make sure it is in the edit_placements subroutine) and replace it with
$cats{ $cat->id } = $cat->label;
my @cats = $cat->parent_categories;
@cats = ($cat, @cats);
my $glue = " > ";
my @res;
while (my $c = pop @cats) {
my $label = $c->label;
push @res, $label;
}
$cats{ $cat->id } = join $glue, @res;
Finally open up tmpl/edit_placements.tmpl and replace the two occurances of style="width: 175px;" with style="min-width: 175px;"
Remember to use the Code Beautifier whilst applying hacks so your code is formatted nicely. Upload all files and you should be done.

David Raynes said:
on Mar 12, 2005 8:32 PM | Reply
If you wanted to use a little bit of Perl magic, you could drop the while loop and change the last line to something like:
$cats{ $cat->id } = join $glue, map { $_->label } reverse @cats;Arvind Satyanarayan said:
on Mar 12, 2005 9:00 PM | Reply
Woah thanks for that David!
Minh Nguyá»…n said:
on Mar 13, 2005 6:26 AM | Reply
How about putting subcategories inside of <optgroup>? That way you won’t have to repeat the name of the parent category over and over again.
Kevin Donahue said:
on Mar 16, 2005 8:56 PM | Reply
Thanks, Arvind! You rock!
NathanNewman said:
on Mar 20, 2005 6:48 AM | Reply
Arvind- This is great.
One small bug is that if you pick a category as the primary category, that same category gets relisted in the multiple category list (unlike in the old listing). This is a problem because if you pick the same category twice, that entry will appear in any list of entries in that category twice.
Maybe to add to your ToDo list is that the categories get listed in two other places-- the initial bookmarklet screen and the list of categories in the power-editing mode.
But thanks for this hack. It's invaluable for a new project I'm working on.
Nathan
rowan said:
on Apr 23, 2005 9:54 PM | Reply
Under MT version 3.16, the placement in the change to the CMS.pm code has moved. It is now in the vicinity of line 2926.
When I upgraded I lost staggered categories in the multiple categories selection box. However, after upgrading the CMS.pm file (at line 2926) and the edit_placements.tmpl it works fine.
Arvind Satyanarayan said:
on Apr 23, 2005 10:01 PM | Reply
Well done on figuring it out rowan! That's why I'm hesitant to put line numbers in hack tutorials. Code remains the same just moves around. Anyways well done!
Anna said:
on May 8, 2005 1:04 AM | Reply
This is fantastic! Easily implemented and a huge improvement over the existing interface. Many thanks.
Anna
Gregory said:
on Nov 11, 2006 9:14 AM | Reply
what exactly does this do?
I'm using MT 3.33.
I use multi-tier categories and I don't like the fact that MT doesn't automatically include upper-level categories when I select any of the non-root categories. I hoped this hack would 'fix' that. I installed it but nothing seems to have changed. I even tried deselecting and reselecting categories for one of my recent entries but the categories for the entry didn't change.
if my categories are: Sports Soccer Cricket
will/should selecting Soccer automatically select Sports?
regards, Gregory
Arvind Satyanarayan said:
on Nov 11, 2006 9:38 AM | Reply
Hi Greg
This hack was for MT 3.1 where the hierarchy of subcategories wasn't correctly displayed. Regarding your problem, MT doesn't currently offer that functionality but perhaps you could use the MTEntriesWithSubCategories tag in your category archive templates - that tag will include all entries from sub categories too.