Site structure
Version 5.x > Site structure > Filtering documents using multiple categories View modes: 
User avatar
Member
Member
rmaspoch - 1/13/2011 10:55:57 PM
   
Filtering documents using multiple categories
We would like to have a way for the users to filter content on the site by selecting one or more content categories.
We were looking at the categories module, but we are not sure on how to set a filter that takes into account multiple categories. Any ideas would be greatly appreciated.

Also, is there a web part we could use to let the users select the multiple categories they would like to filter on? Something similar to the control used in the CMSDesk to associate categories to documents.

Thanks in advance,
Rodolfo

User avatar
Member
Member
kentico_michal - 1/14/2011 4:24:15 AM
   
RE:Filtering documents using multiple categories
Hi,

Regrettably, there is no web part currently available which allows you to filter documents using multiple selected categories. There is just Category list web part which is used to display a list of enabled global and custom categories.

Anyway you could create custom web part which could display list of categories and on the postback you could filter documents depending on selected categories.

If it is not what exactly you want to acomplish could you please specify your request in more detail?

Best regards,
Michal Legen

User avatar
Member
Member
rmaspoch - 1/14/2011 7:09:15 AM
   
RE:Filtering documents using multiple categories
Thanks for your response Michal.

Once we have the selected categories, we would like to filter the out-of-the-box web parts using the selected categories. We understand we might need to create a custom macro to return the selected categories, or something along those lines. The part we are having problems with is how the WHERE condition on those web parts would look like. Can you help?

User avatar
Member
Member
kentico_michal - 1/18/2011 3:48:07 AM
   
RE:Filtering documents using multiple categories
Hi,

Once you have CategoryID parameter of selected categories (CMS_Category table), you can use SelectNodes method (CMS.TreeEngine.TreeProvider class) to get the dataset of documents. This method accept WHERE condition as an input parameter. So you could use standard IN SQL statement in following format:

DocumentID IN (value1,value2,...)

Values value1, value2 you can get from CMS_DocumentCategory table which defines relationship between category and assigned documents.

More information about SelectNodes method can be found in API reference:


Best regards,
Michal Legen