Show related news / blog posts/ events etc. Via categories on a new page template

Eoin Maguire asked on March 31, 2014 06:12

I have various pages on a site that need to show news / events/ blog posts etc. that are related to that section / page of the site.

I've set up various categories and for the purposes of testing I've created a few test news / blog items that are assigned to the same categories. In my aspx page template I need to alter my news repeater to display the various items associated with these categories. The test repeater I have looks like this:

<cms:CMSRepeaterWithEffect ID="CMSRepeater2" runat="server" Path="/%" ClassNames="cms.news" TransformationName="cms.news.preview" EnablePaging="true" TopN="5" SelectedItemTransformationName="cms.news.default" ItemSeparator="


" PageSize="20"> </cms:CMSRepeaterWithEffect>

I'll also need to do this with blog posts etc, what's the best way of achieving this?

Recent Answers


Petar Kozjak answered on March 31, 2014 07:18

Hi,

add to your repeater WHERE condition: WhereCondition="CategoryID = 1"

You can load it from code:

If you are thinking about path as category /News /Events, then just change Path in repeater: Path="/News/%"

Hope this helps

0 votesVote for this answer Mark as a Correct answer

Petar Kozjak answered on March 31, 2014 07:19

Sorry core example:

0 votesVote for this answer Mark as a Correct answer

Petar Kozjak answered on March 31, 2014 07:20

<script runat="server">
  protected override void OnInit(EventArgs e)
    {
      base.OnInit(e);
    var sqlFormattedDate = myDateTime.Date.ToString("yyyy-MM-dd HH:mm:ss");
      NewsRpt.WhereCondition= "CategoryID =  1";
      NewsRpt.ReloadData(true);
    }
</script>
0 votesVote for this answer Mark as a Correct answer

Eoin Maguire answered on March 31, 2014 08:12

Thanks for the replies. So I add a news repeater on the aspx page and then in the code behind I can pass in a wherecondition variable?

Do you know where I could find examples of the generic news repeater or is the repeater I'm using ok for that purpose?

0 votesVote for this answer Mark as a Correct answer

Eoin Maguire answered on March 31, 2014 10:14

This isn't working for me as it's saying that CategoryID is an invalid column name. The news doc type doesn't have categoryID in there but I had assigned the news item to a category, not sure how to query against that relationship though.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 31, 2014 19:17

Are you using .ASPX or Portal mode? There isn't a CategoryID on the Document, because its a many to many relationship. You have to do something like this to get the categories a document is assigned to.

0 votesVote for this answer Mark as a Correct answer

Petar Kozjak answered on April 1, 2014 02:54

Hi, sorry... CategoryID can be get from CMS_Document... Brendan is right.

0 votesVote for this answer Mark as a Correct answer

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