API
Version 7.x > API > Random category and document View modes: 
User avatar
Member
Member
beau.cowan-rrpartners - 8/19/2013 3:29:23 PM
   
Random category and document
We are looking to give the user a unique experience on one of our sites, which means that we want to select a random parent category and a random document from that category.

So far I'm able to select a category that hasn't been used yet, and get documents from that category, but I still need to be able to randomize it with CategoryInfoProvider.GetCategories and TreeHelper.SelectNodes.

If anyone has some suggestions, I'm all all ears... digitally speaking.

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 8/19/2013 6:28:49 PM
   
RE:Random category and document
Hello,

For this purpose you can use e.g. the following method:
CategoryInfoProvider ► GetCategories(Int32)
which returns dataset of all categories for specified site.

After that you can randomly choose one record from this dataset, so you will get a random category.

Another possible solution could be to create a list of all categories and then randomly select record from this list but in general, it's the same you are just able to specify from which categories do you want to select a random record.

Best Regards,
Martin Danko

User avatar
Member
Member
beau.cowan-rrpartners - 8/20/2013 7:02:47 PM
   
RE:Random category and document
Thanks, I'll give it a shot. That's what I figured that we'd have to do, but I didn't know if there was a better way to where I could have the SQL Server help share some of the processing instead of having it all being in the backend.

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 8/21/2013 6:19:44 PM
   
RE:Random category and document
Hi Beau,

Yes, unfortunately there is nothing more that could be helpful in this scenario but feel free to share your working solution with other, I believe it could help somebody in the future.

Best Regards,
Martin Danko