Forum

Thread tagged as: Problem, Blog, Comments

Problem sorting blog posts by postCommentCount

I am trying to created a trending blog posts area on the sidebar of my blog. I am trying to sort the blog posts by comment count, from most comments to least. Below is the code on my blog page to sort by postCommentCount:

                        <?php 
                            perch_blog_custom(array(
                            'template' => 'post_in_list_trending.html',
                            'sort' => 'postCommentCount',
                            'sort-order' => 'DESC',
                            'start' => '1',
                            'count' => '3',
                            ));
                        ?>

It seemed to work correctly until I added more comments to blog posts and the count seems to not be updating correctly.

On the page_in_list.html template, I am using

<perch:blog id="postCommentCount"/>

and the count is updating and displaying correctly. The template for post_in_list_trending.html is below:

<div class="trending_post">
        <a href="<perch:blog id="postURL" />"><img src="<perch:blog id="blog_image" type="image" width="220" height="300" crop="true" />" alt="<perch:blog id="postTitle" />" /></a>
        <div class="trending_ribbon">
            <p><a href="<perch:blog id="postURL" />"><perch:blog id="postTitle" /> <i class="icon-comment-1"></i> <perch:blog id="postCommentCount"/></a></p>
        </div>          
</div>

Any ideas on why this isn't working correctly? Thanks

Rick Sellers

Rick Sellers 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you re-save the post, does it update?

I just went through and saved all the blog posts again and it is now working. Thanks!

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, the problem is the posts aren't being reindexed when the comment count changes. I'll need to fix that in Blog.