Custom Category Filter for BlogPosts

Conor Dunk asked on September 22, 2016 12:28

Hi,

Has anyone created a custom filter in Kentico 9 for categorys?

Every resource online is very outdated now.

Thank you, Conor

Recent Answers


Chetan Sharma answered on September 22, 2016 12:38

Yes I have created, however what exactly is your use case?

0 votesVote for this answer Mark as a Correct answer

Conor Dunk answered on September 22, 2016 12:44

Hi Chetan,

We have a news section and the business would like a dropdown field with all the categorys, then when selected would update the data source and display only the categorys which match that dropdown.

Thank you, Conor

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 22, 2016 13:20

You can do this in about 10 minutes using a smart search index on the resources and a smart search filter getting those categories and assigning that filter to the smart search index results. This involves writing NO code and using out of the box web parts.

The information you've found regarding creating a custom filter has not changed significantly over 8 years that's why it's dated.

0 votesVote for this answer Mark as a Correct answer

Leon Kemp answered on September 23, 2016 13:37

Hi Brenden, I am following your instructions above. I have a SmartSearchbox search that produces a SmartSearchResult on a search results page. On the results page I have a SmartSearchFilter which I am filtering the news search results items by category. Search dialog web part ID = SmartSearchResults Query name = CMS.Root.smartsearchcategories. Filtermode = dropdown list.

The list has all the categories in it, however the results page does on re-filter by category when I select a category from the dropdown list.

The problem is the search results are not being filtered by the selection of category.

Do you have a example I am able to look at, or steer me in the right direction.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 23, 2016 17:32

Create a custom query in the Root page type and the query should look like so:

SELECT 'DocumentCategoryIDs','','Select an entry' UNION
SELECT 'DocumentCategoryIDs', CategoryID, CategoryDisplayName FROM CMS_Category WHERE ##WHERE## ORDER BY ##ORDERBY##

In the WHERE Condition add the following:

CategoryEnabled = 1 and CategoryNamePath like '/Your Path in Categories/%' and CategoryUserID is null AND (NOT EXISTS(SELECT CategoryID FROM CMS_Category AS pc WHERE (pc.CategoryEnabled = 0) AND (CMS_Category.CategoryIDPath like pc.CategoryIDPath+'/%')))

Make sure you have the checkbox in the webpart properties for "Filter auto postback" checked otherwise it won't automatically post back and search, you'd need to invoke a postback with another button or something else.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.