2009-05-04

Filtering by category in Zikula

My CMS of choice has been Postnuke for a few years. That project has changed its name to Zikula a while ago. Lots of new features came up, but while features and functions were about the most important thing for me when I was much younger, I have since learned that the best software is pretty useless without proper documentation. And unfortunately, this is an area where Zikula has a few shortcomings.

With Zikula a new way to categorize content came along. Postnuke used topics (hence the module name Topics), and only one topic could be assigned to an article or other element. Zikula uses categories, and the module name is - you guessed it - Categories. With this module, you can create a hierarchical tree of categories and assign at least two to an element. For example, an article dealing with the excellent OmegaT could have "translation" as main and "computer" as secondary category. This way, you can find the article through both categories.

Well, you could find it - if you could filter by categories. It is possible, yes, but basically not documented. After finding out myself I modified the relevant article in the Zikula wiki, but here is the basic idea in case that site starts to wobble again:

First you need to find out how your module of choice lists or displays content. The News module does not know "list", only "view", so you need a link like this:

index.php?module=News&func=view&prop=Main&cat=cid

You may not need "prop=Main", but the News module uses it by default. To find out the correct value to put in for "cid", head over to the categories module and check the properties of the category you want, the ID will be listed.

But what I was really after was this method for the Content module. That's a very useful module if you want to create an article in multiple languages, and display the version corresponding to the interface language chosen by the visitor. If that language version is not available, then the main language version will be displayed. I really love that module, because it shows an article in different languages under the same URL. (I know there are arguments against this, but for the time being, this is the best choice for multilingual documents in Zikula.)

Content needs the "list" function to show you a list (document titles) of all documents, so let's add the category filter and voila:

index.php?module=Content&func=list&cat=cid

Just replace "cid" with the category ID by which you want to filter. You can use this in templates or documents, to filter your content. You might now ask "Fine, but how can I filter by multiple categories?" My simple answer is: No idea. Sorry, but until Valen or someone else enlightens me, I'm afraid I can not give any other answer.

No comments: