Using repeater to show content from same category as parent page

Michael Ollinger asked on July 6, 2017 13:43

On Page A, I'm using a repeater to show pages B, and I want to limit the content being shown via the repeater that share the same category as the page A. Is this best handled via the Category name content filter or through a WHERE clause? Either way, can someone tell me the best way to achieve my goal?

Recent Answers

Brenden Kehren answered on July 6, 2017 14:51

For something like this I set a category on the parent in a separate field (not the normal category setup) and then set the repeater's category with a macro. For instance, /Page-A I add a text field called PageCategory and set the control to a single category selector. Then in the repeater on /Page-A I set the category with macro {%PageCategory%}.

Seems sometimes redundant but it works well and doesn't require a complex WHERE statement.

1 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on July 6, 2017 14:59

You can use where clause for the query and use the LIMIT attribute to limit the no of results without specifying in the query.

I also do something similar as Brenden. I will tie PageCategory to my page type and use it as a filter for where clause and use LIMIT to restrict results.

1 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on July 6, 2017 16:09 (last edited on March 24, 2018 12:15)

You have a document of type A with categories from parent and you want to show document of type B with matching categories. You can use repeater with a custom query, create a query something like:

select DocumentName, DocumentURLPath, CategoryID, * from View_Type_B_Joined vw join cms_documentCategory dc on vw.DocumentID =  dc.documentid
where ##WHERE##  and published = 1

And then in WHERE property of web part you put macro CategoryID in ({% String.Join(",",CurrentDocument.Parent.Categories.IDs)) %}) It is much faster, no DB call. Make sure your check 'Search on each page load' property

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 6, 2017 16:46

Keep in mind using a specific page type's view AND published = 1 in your WHERE clause will not work in version 9 and newer as the specific views for page types were removed and so was the published flag.

0 votesVote for this answer Mark as a Correct answer

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