Need someone to lead product management at your software company? I create software for people that create software and I'm looking for my next opportunity. Check out my resume and get in touch.

Different templates for different categories

Freshness Warning
This blog post is over 19 years old. It's possible that the information you read below isn't current and the links no longer work.

Here’s some more cleaning out my idea database. This is yet another half-conceived idea that if you want to take it, flesh it out, and run with it, it’s yours.

I get asked on occasion how to get Movable Type to use a different templates for each category on the blog. Now that you can segment your site with subcategories, I suspect that more people will want to do this. So here’s a rough outline of how. Please don’t link to this as a tutorial. I don’t want confused MT users to have to sift through my barely coherent ramblings. But if you want to write up a tutorial on how to do this, put a link to it in the comments.

You can have as many category templates as you want. Create a different one for every category.

You can have MT create a different archive file for each template.

Instead of using the category link tags that MT provides, create your own links to the category archive file you want to use for a particular category.

So you might create a category template called news and one called products. Then you change the archive filename format in the MT preferences to output two sets of archive files. One using your news templates and one using the products template. Then in your site, you change the links from <MTArchiveLink> to a manual link like /path/to/the/news/archive/files

So your links now point to a different set of templates depending on what category you want.

KO
September 9, 2004 3:08 AM

This isn't a very elegant way of going about things - this way if you have n categories then you end up having n different templates for each category! And one of the main advantages of a cms is not having to make manual links in the first place. Ideally, you could make any number of category templates, and for each category select which template (or templates) that category should use. This doesn't seem to hard to implement either - MT already stores metadata about each category, so this is just one additional thing to store - the preferred template.

Stefan Seiz
September 9, 2004 4:45 AM

Coincidentially i was fighting with the very same problem yesterday. I ended up simply installing an MT-Plugin called "Supplemental Category Tags" . With this plug in, i can have conditional tags in my Templates which for instance restrict one template to only list a certain category or print special headers based on the category (the user clicked on). Here's a code-snippet from my CategoryArchive Template which prints a special header only for one certain category: print special header... This plugin even supports regex if the regex MT plugin is intalled. I really wonder why MovableType doesn't have any Conditional Category TAGS built in yet. Stefan

Stefan Seiz
September 9, 2004 4:48 AM

gosh, your mt ate my link to the plugin and my example code ;-) Here's the link to the plugin: http://www.stefanseiz.com/cgi-bin/mt.cgi?__mode=view&_type=template&id=11&blog_id=1 And the sample code (hopefully it works this time): <MTIfCategory name="CGVirusScan">    print special header... </MTIfCategory>

Scott Houchin
September 9, 2004 5:57 AM

I've done a couple sites with different templates for different categories, but none of the solutions were all that satisfactory. The best solution I've found was to use the IncludePlus plug-in. This plugin defines an MTIncludeModule container tag. The name of the module to include is contained in the contents of that tag. What you can then do is something like this: The only downside to this is that you either * Need to have custom templates for every category, without fail * Need to have other logic in the template to do something else for categories that don't have custom tags. What I would love to see is a "default" attribute to MTIncludeModule, which specifies the template to include (or even to just skip it) if the module specified by the contents doesn't exist.

Deane
September 10, 2004 7:31 AM

I've wanted to do this for years, but never got around to it. I was thinking that you could include another template based on the category using some kind of control structure (with a default for the "standard template"). For instance, if the category is "cars," include template module called "cars.tmpl" or something. There's got to be a plugin out there that would supply the pieces for this. On another note, it's odd that this hasn't been built into MT. Using Brad's KayValue plugin with this, would allow you to kludge your way into the "store any object" Nirvana of content management.

thomas
September 20, 2004 5:42 AM

I can't help feeling this isn't right or elegant, but what about using one nasty, complicated template file for everything, and dynamically generating a category-specific link to an extra css file to manage the look and feel of each category? the MT line would be something like: .css" type="text/css" /> so if the entry's main category is category1, this would create a link to "category1.css". This obviously doesn't help much if you assign the entry to several categories and want it treated with a different template each time you approach it from a different archive index. One possible advantage I can see is that even if the css file isn't present, nothing much goes wrong... not the case if you start to replicate template files and mis-name them, miss bits out or forget to build them. It would be so much nicer if you could select a default template for each category or entry (or both, with a level of override priority?) as you set them up in MT, of course...

Josiah Hincks
December 5, 2005 5:18 PM

I don't think there is any elegant solution if you need differential HTML markup for entries in different categories. A more modest and managable approach for static pages where you only need differential CSS might be: (1) Have a default CSS file that is always applied. (2) Have an additional category specific CSS file that a link is made to using MTIfCategory (from the Supplemental Category Tags plugin). There is no need to either create or customise the category specific CSS file unless you needed it since the default layout would be applied.

Henning von Vogelsang
June 12, 2006 3:31 AM

Applying a different CSS for each category might help to change the background color or some used images and font styles, but it doesn't change the structure, which is stored in XHTML. So if I want to actually change the design of the page (different placement of elements), not just its looks, the approach with multiple style sheets won't work. The plugin using is conditional. It works well to show/hide certain elements. A while ago I made a website using this method to display different header images per category. If you want to use the link list to all categories, automatically generated by Movable Type, Adam's solution won't work for you. However, with the MTInclude tag, you could generate a new 'automatic list' by your own, which you would have to change only in one instance, in your modules (MT 3.2).

Adam Kalsey
June 12, 2006 10:15 AM

Henning: CSS can do a LOT more than change colors and images. The entire layout can be changed using CSS. See http://www.csszengarden.com/ for some examples. All those designs use the same HTML file, just different stylesheets.

This discussion has been closed.

Recently Written

Too Big To Fail (Apr 9)
When a company piles resources on a new product idea, it doesn't have room to fail. That keeps it from succeeding.
Go small (Apr 4)
The strengths of a large organization are the opposite of what makes innovation work. Starting something new requires that you start with a small team.
Start with a Belief (Apr 1)
You can't use data to build products unless you start with a hypothesis.
Mastery doesn’t come from perfect planning (Dec 21)
In a ceramics class, one group focused on a single perfect dish, while another made many with no quality focus. The result? A lesson in the value of practice over perfection.
The Dark Side of Input Metrics (Nov 27)
Using input metrics in the wrong way can cause unexpected behaviors, stifled creativity, and micromanagement.
Reframe How You Think About Users of your Internal Platform (Nov 13)
Changing from "Customers" to "Partners" will give you a better perspective on internal product development.
Measuring Feature success (Oct 17)
You're building features to solve problems. If you don't know what success looks like, how did you decide on that feature at all?
How I use OKRs (Oct 13)
A description of how I use OKRs to guide a team, written so I can send to future teams.

Older...

What I'm Reading

Contact

Adam Kalsey

+1 916 600 2497

Resume

Public Key

© 1999-2024 Adam Kalsey.