API Questions on Kentico API.
Version 6.x > API > Reading newsitems by category View modes: 
User avatar
Member
Member
Regus - 9/24/2012 6:48:20 AM
   
Reading newsitems by category
In one of my webparts I use this code to get all newsitems
DataSet documents = tree.SelectNodes(CMSContext.CurrentSiteName, "/%", "en-US", false, "CMS.News");

Now, I need to get only the items from category 'myCategory'. I understand I need to do this in the parameter "where". But I don't know the format of this clausule.
Could someone give me an example ?

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 9/24/2012 7:08:26 AM
   
RE:Reading newsitems by category
Hi,

it is not so simple as connection between documents and catagories is stored in a different table.

You can define where clause like

DocumentID IN (1, 2, 66)

The IDs od documents you can get from CMS_DocumentCategory table.

SELECT DocumentD FROM CMS_DocumentCategory WHERE CategoryID=44


Your final code will be something like:

DocumentID IN (SELECT DocumentD FROM CMS_DocumentCategory WHERE CategoryID=44)


The CategoryID you can find in the CMS_Categery table.

Best regards,
Ivana Tomanickova