+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / viewCount and commentCount issue for blogposts

viewCount and commentCount issue for blogposts

4 posts, 0 answered
  1. Phani
    Phani avatar
    9 posts
    Registered:
    18 Mar 2014
    03 Apr 2014
    Link to this post

    hi, I need to display titles of all blogposts sorted by viewCount desc in one list and by commentsCount desc in another list. I have the following, but doesnt seem to work.....what am I doing wrong here......

    protected void getBlogPosts()
            {
                BlogsManager blogsManager = BlogsManager.GetManager();

                List<BlogPost> postsList = blogsManager.GetBlogPosts().Where(t => t.Status==ContentLifecycleStatus.Live).ToList();

                for (int i = 0; i < maxItemstoShow; i++)
                {

                    
                    BlogPost post = postsList[i];

                    int commentsCount = post.Comments.Count;
                    int viewCount = post.ViewsCount;
                    plhBlogsList.Controls.Add(new LiteralControl("<div class=\"post_titles_container\"><div class=\"newsitem\"><a href='/news/" + post.ItemDefaultUrl + "'>" + post.Title + "</a></div></div>"));
                }

                
            }

     

    commentsCount and viewCount always return 0, even when I have comments and views for a particular blogpost. Is this not the right way of looking for those counts?

    Or is there a setting within Sitefinity dashboard that I need to turn on/off to make the counts work?

    Thanks,

     

     

  2. Martin Gebov
    Martin Gebov  avatar
    15 posts
    Registered:
    03 Nov 2016
    15 Apr 2014
    Link to this post
    Hello,

    Due to refactoring in the comments module, there is a new API for accessing comments and comment related data. Please refer to this doc article.

    As for the ViewsCount property, after some research it turns out that this property was meant for future implementations. There is no implementation for it and it could not be used at the moment.

    Regards,
    Martin Gebov
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Jonathan
    Jonathan avatar
    119 posts
    Registered:
    19 Dec 2012
    16 Jan 2015 in reply to Martin Gebov
    Link to this post

    Sorry I'm alittle late to the party.  Here is a gist on how i got it to work for News.  The helper method is there for blogs and is just a matter of changing the method being called.

    https://gist.github.com/jonathanread/61a9e710f569753b98d7 

     

    here is another link: https://plus.google.com/102002593277452935883/posts/DdrKoHtQXj5

  4. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    21 Jan 2015
    Link to this post
    Hi Jonathan,

    Thank you for the shared solution with the community.

    Regards,
    Svetoslav Manchev
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
4 posts, 0 answered