viewCount and commentCount issue for blogposts

Posted by Community Admin on 04-Aug-2018 13:32

viewCount and commentCount issue for blogposts

All Replies

Posted by Community Admin on 03-Apr-2014 00:00

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,

 

 

Posted by Community Admin on 15-Apr-2014 00:00

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
 

Posted by Community Admin on 16-Jan-2015 00:00

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

Posted by Community Admin on 21-Jan-2015 00:00

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
 

This thread is closed