viewCount and commentCount issue for blogposts
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,
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
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.
gist.github.com/.../61a9e710f569753b98d7
here is another link: plus.google.com/.../DdrKoHtQXj5
Hi Jonathan,
Thank you for the shared solution with the community.
Regards,
Svetoslav Manchev
Telerik