Help - Search - Members - Calendar
Full Version: Single category with multiple descriptions
Movable Type Community Forum > Additional Resources > Tips and Tricks
followben
I want to have 2 descriptions assigned to my categories:
  • a short version to display on the category index page
  • a longer version to display on the individual category archive page

I'd preferably want to enable this on a blog-by-blog basis. Does anyone have any bright ideas how it could be achieved?
houchin
I'm not sure if you'll call this a good way to do it, or if you'd call it a hack, but you can use MTIfMatches from Brad Choate's Regex plugin.

As an example, I have the following in my category archives to show a link to the Adobe Reader download in my category for PDF files:

CODE
<MTIfMatches var="ArchiveTitle" value="Print edition">
<!--#include virtual="/get-adobe-reader.html.frag" -->
</MTIfMatches>


The unfortunate part is that you would need to have a whole series of these MTIfMatches statements (one for each category) on both your category index and individual category archive pages. If you added a category, you would then need to update your templates.

I've found that the best way to solve most problem like this (when you want to add conditional content) is to think like a programmer, not like a web designer. Templates are as much computer programs as they are HTML files with special codes.

Scott
followben
Thanks Scott, I hadn't considered that. I'm already using quite a few of Brad's nifty plugins, including Regex.

The difficulty is that I'm using Category archiving to create "galleries" in a photoblog, with 1 category for every series of photos. In this circumstance its less than ideal to have to update the template code every time I want to upload a new gallery, but its certainly an option.

Any other ideas?

Ben.
houchin
If you're willing to create an index template per gallery, you could just make simple templates that just contain the descriptions in plain text.

You could then try and use Brad's macro plugin or something like that with MTInclude to include the build version of that template. I haven't used the Macro plugin, but from perusing the docs, I think you could algorithmically construct an MTInclude statement that contained the primary category name and dirify it. You'd then just need to make sure that your new index.

If you didn't want to go to the trouble to create those index templates, you could just manually create those files and upload them.
trialanderror
Just a suggestion. Please read the caveat first.

1. Create two files for each category:
catnamelong.html
catnameshort.html

This is under the assumption that your descriptions will be different for each category. In the code below "catname" is replaced with the MT tag MTCategoryLabel, you may be able to use MTEntryCategory. (I am unsure in your particular context which one you need to chose).

2. Use MTIncludePlus and MTCategoryOfArchive (plugins). In the category index template

CODE
<MTIncludeModule><MTCategoryOfArchive><MTCategoryLabel>short.html</MTCategoryOfArchive></MTIncludeModule>


In the other (individual entry category?)template

CODE
<MTIncludeModule><MTCategoryOfArchive><MTCategoryLabel>short.html</MTCategoryOfArchive></MTIncludeModule>


Your .html files would be stored in either Local Site Path directory or your Local Archive Path directory.

Caveat.
I have not personally tested this so I am really unsure whether this actually works, but in theory...

t&e
crys
Try using the KeyValues plugin to keep both discriptions in the single field.

CODE
longdescr==
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam cursus, elit scelerisque varius tempor, tortor tellus aliquam ligula, non vestibulum dui odio id erat. Morbi dolor turpis, imperdiet eu, egestas et, pellentesque id, felis. Nunc et pede. Maecenas dignissim tortor sed ipsum. Pellentesque sit amet mauris. Proin sed risus. Quisque vitae sem ac sem tempus aliquam. Curabitur elit erat, dapibus eu, dapibus ac, luctus a, felis. Ut congue dolor id nibh. In sit amet lectus nec lorem aliquet viverra. Nunc vulputate, augue id pulvinar rhoncus, arcu erat ullamcorper lectus, quis pretium libero tortor vitae mi. Praesent diam turpis, luctus vitae, fringilla in, aliquam id, urna. Nulla vitae magna. Aenean eget arcu. Proin nibh. Curabitur suscipit, odio id molestie hendrerit, nibh metus eleifend odio, ac ullamcorper ligula turpis luctus odio. Curabitur wisi quam, ullamcorper sit amet, pharetra a, semper nec, diam. Pellentesque tempus erat eget lectus. Donec vitae purus sit amet ipsum cursus hendrerit.

Sed interdum lectus ut risus. Donec sagittis. Sed semper pede vitae urna. Mauris et mauris. Nam condimentum, eros vel ornare lacinia, augue diam ornare dolor, auctor tempor felis elit ut nunc. Pellentesque sed ante ac est lacinia mattis. Donec suscipit suscipit nibh. Aenean volutpat lacus laoreet augue. Donec id eros. Mauris ultricies nonummy sem. Sed pellentesque. Etiam vestibulum, lacus eu semper fringilla, neque augue convallis pede, nec rhoncus ipsum arcu ut velit. Duis massa orci, dignissim id, laoreet ac, rutrum quis, enim. Quisque tempor. Nulla ornare, est id rhoncus ultricies, libero nulla eleifend dui, eget fringilla leo ipsum ac odio. Nam quis dolor. Aliquam tincidunt mauris at augue.

Nullam egestas ipsum quis enim. Aenean dapibus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc a eros sit amet nibh congue rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum leo lectus, semper ac, placerat id, sodales nec, odio. Duis venenatis viverra tortor. In sagittis risus non odio. Nam tortor massa, consequat in, eleifend nec, vestibulum sit amet, ipsum. Pellentesque at purus id urna dictum nonummy. Sed purus. Nulla tincidunt massa euismod nulla.
==longdescr
shortdescr==
Cras mollis porta lacus. Cras quis dui. Ut mi libero, blandit non, convallis ac, ullamcorper nec, quam. Cras lorem felis, hendrerit id, scelerisque sit amet, scelerisque sit amet, magna. Nullam dignissim augue eget orci. Aliquam libero leo, euismod quis, bibendum sit amet, sollicitudin at, pede. Integer orci. Curabitur tellus leo, pretium in, tincidunt vitae, bibendum id, magna. Curabitur sed tellus. Sed et libero.
==shortdescr


CODE
<MTKeyValues source="[MTCategoryDescription]">
<MTKeyValue key="longdescr">">
</MTKeyValues>
houchin
QUOTE (trialanderror @ Aug 6 2003, 11:55 AM)
In the other (individual entry category?)template

CODE
<MTIncludeModule><MTCategoryOfArchive><MTCategoryLabel>short.html</MTCategoryOfArchive></MTIncludeModule>

After thought, though, I think I like the KeyValues solution, pulling the data out of the CategoryDescription.

But if you want to go with separate included files (because you want to update the descriptions other than through the MT interface), you can simplify things by using plain old server side includes instead of MTInclude or MTIncludePlus. I do this to link a standard navigation column into all of my pages, as well as a couple other things. The benefits of SSI are that you can modify your descriptions without rebuilding your site, and the syntax in your templates will be cleaner.

My assumption has been that by your "category index" you mean the index that lists all of your categories on one page, and that by your individual category indexes you mean your pages, one per category, that list all of the entries in that category.

In your category index template, you'd have a line like:

CODE
<MTArchiveList archive_type="Category">
...
<!--#include virtual="/<$MTArchiveTitle dirify="1" $>short.html" -->
...


On the page that lists the entries for a particular category, you'd have something very similar, but possibley with the "long" description.

If you wanted this description on the actual individual entry page, it would again be similar but instead of using MTArchiveTitle, you'd use MTEntryCategory
kadyellebee
I see you've gotten a lot of suggestions -- just thought I'd point out the ExtendedAttribute plugin, since the description of the plugin fits what you need really well smile.gif

Kristine
followben
Thanks folks, both for the info and the quick response.

I reckon either of the ExtendedAttribute or KeyValues plugins will do the job. I'll investigate both, see what works best, and let you know how I go.

Now, if only someone could solve my problem using thumbailing in MT...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.