scriptygoddess

20 Sep, 2003

Main and secondary categories in MT (with a little help from PHP)

Posted by: Jennifer In: Script snippet

The point of this script-snippet is so you can set up two hierarchies of categories. So there's a main category, and a few "sub-categories" below it. An example of this is on Christine's Pixelog site, on her album page.

This differs from the way MT has "Primary" and "Secondary" categories in that in mine, the sub-categories for a main category, can only be a sub category of that one main category – not any other main category. Here's another example: Ohnozone.net . In the sidebar, scroll down to the "categories", You'll see there's a main category "Appearances", and there's sub categories beneath it. "Interviews & Articles" and "TV"

So the biggest trick of this is that you name your categories in a consistent manner. In the example at Ohnozone – the categories are "Appearances – Interviews & Articles". The next category is "Appearances – TV". So the "Main" category is always the first part of your category name.

When we go to display the list, for each main category, you need the following block:

<?
$sortingCategory = "MAIN CATEGORY";
$removeAddtlnchars = SOMENUMBER-NOQUOTES!;
//————————————–
$numchars = strlen($sortingCategory);
$displayafterchars = $numchars + $removeAddtlnchars;
?>
<p><b><? echo $sortingCategory; ?></b></br>
<MTArchiveList archive_type="Category">
<?
$cat = "<$MTArchiveCategory$>";
if (!strncmp($cat, $sortingCategory, $numchars))
{
print ('<a href="<$MTArchiveLink$>">'.substr("<$MTArchiveCategory$>",$displayafterchars).'</a></br>');
}
?>
</MTArchiveList>
<p>

You'll only be modifying what's in bold/red. So here's how this works. Let's use the example of this Main/Sub category:

Appearances – Interviews & Articles

We'd set the value of $sortingCategory to "Appearances". In this example, we're seperating the "Main" category from the "Sub" category with " – " (a space, then a dash, then another space) that's three "characters". So we set the value of $removeAddtlnchars to 3.

Copy that block, and make those two adjustments for each "main" category you have.

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

11 Responses to "Main and secondary categories in MT (with a little help from PHP)"

1 | Garinungkadol

September 22nd, 2003 at 9:07 pm

Avatar

MTCategory Bliss!
David Raynes has come out with a subcategory plugin while the lovely gals at scriptygoddess have come up with this…

2 | Christopher Trott

December 12th, 2003 at 7:15 pm

Avatar

I am trying to list my categories via Movable Type. What tag do I use? any help would be greatly appericated.

chris

3 | david arthurs

January 14th, 2004 at 2:05 pm

Avatar

Can you tell me where you place that code? I am relatively new to MT.

Do you have to create a seperate tempate for each category and then place that code in each category template code?

4 | david

January 15th, 2004 at 10:22 am

Avatar

how do you get the rest of your main menu categories (that don't have sub cateoires to show) to show ? and if you use that script on the index.phph page it seems to show the full category name with hypen and subcategy etc., – how do you just get the main category 'Appearances' to show on the homepage?

5 | Jennifer

January 15th, 2004 at 11:07 am

Avatar

David – you can put that code in any template you want the list to display in. (You don't need a seperate template) – as for your other questions – I'm not following what you're doing. If you can email me the code you have on your page, and a link to where it's displaying – I might be able to help. (email is: scripty AT scriptygoddess DOT com)

Christopher – "I am trying to list my categories via Movable Type." You can find that answer in the movable type manual.

6 | Christopher Trott

December 12th, 2003 at 7:15 pm

Avatar

I am trying to list my categories via Movable Type. What tag do I use? any help would be greatly appericated.

chris

7 | Patti

October 10th, 2003 at 11:44 am

Avatar

i'm so sorry, last one for sure…

a .txt file version of the php Category Archive page that has the error.

8 | Patti

October 10th, 2003 at 10:52 am

Avatar

hi good morning. i have to be honest in saying that i am pretty overwhelmed…

Parse error: parse error in /home2/blh2o3/bicusa-www/bicusa/issues/africa/index.php on line 200

site: http://www.bicusa.org/bicusa/

site map: http://www.bicusa.org/bicusa/categories.html

code is located at :
http://www.bicusa.org/bicusa/categoty_archive.txt

yes, i did modify the original code.

i also made a post at moveabletype.org, but i didn't explain myself very clearly. i figured since this is your script, you would know best.

any help on this would be MUCH MUCH appreciated. thank you.

best,
patti

9 | Patti

October 10th, 2003 at 11:20 am

Avatar

Ooops… I forgot to add the link to my moveabletype.org post.

post on moveabletype.org

10 | ceejayoz

September 21st, 2003 at 5:40 pm

Avatar

You really shouldn't use PHP's short tags – use the full <?php ?> notation.

Short tags are often disabled and thus will cause problems on some sites.

11 | Christine

September 20th, 2003 at 7:40 pm

Avatar

Just yesterday I discovered that David Raynes has released his subcategory hack at:
http://www.rayners.org/2003/08/19/subcategories.php

I found it at Jay Allen's site, and he added additional "recipes" for it which he offers here:
http://www.jayallen.org/misc/tutorials/subcat_mt_plugin/

His full post about it is here:
http://www.jayallen.org/journey/2003/09/subcategories_plugin_for_mt

(I was going to post all of this here, but realized it tied in to this post. I can make it a separate one if you want me too.)

Featured Sponsors


  • Curt: If anyone comes across this with similar issues I was able to sort out the pagination issues painlessly with easyCommentsPaginate from http://www.mush
  • Christopher: Yeah, it is indeed hard to do. And something remains elusive about why the pagination never worked. I tried everything I could find. Regardless, I
  • Jennifer: Hi Christopher, always hard to bug test stuff like that remotely. Sorry those didn't help. Glad you found a solution though :)

About


Advertisements