Need someone to lead product or development at your software company? I lead product and engineering teams and I'm looking for my next opportunity. Check out my resume and get in touch.

Different templates for different categories

Freshness Warning
This article is over 15 years old. It's possible that the information you read below isn't current.

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

A framework for onboarding new employees (May 15)
There’s no single good way to onboard an employee that works for every role. Here's a framework for creating a process that you can adapt to each situation.
TV hosts as a guide for software managers (May 10)
Software managers can learn a lot from journalists or late night TV hosts and how they interview people.
The Improvement Flywheel (Apr 29)
An incredible flywheel for the improvement of a development team. Fix a few things, and everything starts getting better.
Managers and technical ability (Dec 26)
In technical fields, the closer you are to the actual work being done, the closer your skills need to resemble those of the people doing the work.
Dysfunctions of output-oriented software teams (Sep 17)
Whatever you call it, the symptom is that you're measuring your progress by how much you build and deliver instead of measuring success by the amount of customer value you create.
Evaluative and generative product development (Aug 30)
Customers never even talk to the companies that don't fit their needs at all. If the only product ideas you're considering are those that meet the needs of your current customers, then you're only going to find new customers that look exactly like your current customers.
Product Manager Career Ladder (Aug 19)
What are the steps along the product management career path?
Building the Customer-Informed Product (Aug 15)
Strong products aren't composed of a list of features dictated by customers. They are guided by strong visions, and the execution of that vision is the primary focus of product development.

Older...

What I'm Reading

Contact

Adam Kalsey

+1 916 600 2497

Resume

Public Key

© 1999-2020 Adam Kalsey.