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.

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

1 | 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.)

2 | 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.

3 | 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

4 | 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

5 | 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.

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 | 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

8 | 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?

9 | 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?

10 | 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.

11 | 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…

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements