More in this section

Forums / Developing with Sitefinity / Most Discussed Custom Widget

Most Discussed Custom Widget

2 posts, 1 answered
  1. Raymond Dowe
    Raymond Dowe avatar
    37 posts
    Registered:
    10 Mar 2010
    28 Feb 2012
    Link to this post
    I'm hoping someone can give me some help with a custom widget I'm developing. I think all I actually need is syntax help.

    I'm creating a custom widget to display the most discussed blog posts. That has gone well, and I have the ability to specify a certain number of blog post summaries to show up, ordered by how many comments they have. This is the code I'm using:

    int count = int.Parse(_maxNumberPosts); // this is a public property on the control
    var recentPosts = App.WorkWith().BlogPosts().Publihed().OrderByDescending(b => b.Comments.Count).Get().Take(count);
    rptblogMostDiscussed.DataSource = recentPosts;
    rptblogMostDiscussed.DataBind();

    What I would like, is to add a second public property, so that when placing the control on a page, you can specify for how many days comments should be considered. For example, if I set it to 14, it would only consider comments made in the last 2 weeks, instead of the way it currently works which uses a lifetime grand total of all comments.

    Can someone help me as to how I would do this?
  2. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    02 Mar 2012
    Link to this post
    Hi Raymond,

     What I can suggest here is adding a DatePicker control (for example) and wiring it up to a property in your code-behind. Then in the query, you can use the selected value from the DatePicker and using a Where clause, before the OrderByDescending command, filter the blog posts by Comment.PublicationDate for all the dates that are after the selected one. Let me know if you have specific questions on the implementation (syntax) for this.

    Greetings,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
2 posts, 1 answered