ASPX templates
Version 4.x > ASPX templates > Category List Webpart View modes: 
User avatar
Member
Member
gogreen-gmail - 3/31/2009 4:53:05 PM
   
Category List Webpart
How do I display items related to a specific 'Category' in a page. I am currently using "Categorylist" and "Repeater" webpart. Is there any 'Where' condition that I can use to retrive items under a specific category?

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 4/15/2009 7:25:31 AM
   
RE:Category List Webpart
Hello,

You can use following where condition for repeater:

'{%categoryid%}' = '' OR (DocumentID IN ( SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID = '{%categoryid%}' ))

Best Regards,

Martin Dobsicek

User avatar
Certified Developer v7
Certified  Developer v7
Gitesh - 5/30/2012 12:05:05 AM
   
RE:Category List Webpart
Hi Martin,

This is exactly what I was looking for.

But the macro '{%categoryid%}' doesn't retrieve any value for me in the repeater where condition.

It works when I write the below code:

(DocumentID IN ( SELECT DocumentID FROM [Northtec-Staging].[dbo].[CMS_DocumentCategory] WHERE CategoryID = '12' ))


It doesn't work with the below code (I think it is because of the macro):

(DocumentID IN ( SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID = '{%categoryid%}' ))


Thanks
Gitesh Shah

User avatar
Member
Member
kentico_michal - 5/30/2012 3:51:27 AM
   
RE:Category List Webpart
Hi,

Are you sure that the there is a categoryid URL parameter?

Could you please enable the Sql debug to see the resolved macro value.

Best regards,
Michal Legen

User avatar
Certified Developer v7
Certified  Developer v7
Gitesh - 5/30/2012 4:17:15 AM
   
RE:Category List Webpart
Hi Michal,

Sorry for being completely dumb. Didn't realise that it is a URL macro.

Is there a way to find out the CategroyID of the Document with a macro?

Thanks
Gitesh Shah

User avatar
Member
Member
kentico_michal - 5/30/2012 7:23:38 AM
   
RE:Category List Webpart
Hi Gitesh,

A document can be assigned to multiple categories. If you are using Kentico CMS 6.0, you can use the following code to loop through all categories assigned to a document:

foreach (CategoryInfo info in treeNode.Categories)
{
}


where the treeNode is the CMS.TreeEngine.TreeNode object.

Best regards,
Michal Legen

User avatar
Certified Developer v7
Certified  Developer v7
Gitesh - 6/19/2012 6:04:58 PM
   
RE:Category List Webpart
Hi Michal,

Can you please refer me to a documentation related to this as I am not sure which file to edit and how to retrieve the category names.

Thanks
Gitesh Shah

User avatar
Member
Member
kentico_michal - 6/27/2012 2:33:51 AM
   
RE:Category List Webpart
Hi Gitesh,

To be honest, I am not sure what documentation you mean. Could you please be more specific? A document can be assigned to multiple categories. To get a list of categories assigned to a document, you need to query the CMS_DocumentCategory database table. Of course, you can also use API as mentioned in previous post.

Best regards,
Michal Legen