Rearranging comments to display the latest comments at the top has become a new trend, and more and more blogs implement this comment on their website. If your blog has a lot of user interactions, then you will choose this option because usually the most recent comments will be hidden on the last page or bottom. In this article, I will show you how to rearrange comments in WordPress and display the latest comments at the top.
There are multiple ways that have been available online and some even require us to edit our core files. Editing core files is not a good option because every time we upgrade WordPress, we have to make that change again. We have got two ways that we can use to rearrange the comments and display them in their descending order showing the most latest comment first that will not require us to change the core files at all.
This method requires us to add a very simple code to our comments.php. First, we need to find this line:
foreach ($comments as $comment) {
Note: These may vary slightly in the different themes. Now immediately before this line, we need to add:
add
$comments = array_reverse($comments);
With this reverse function, we can rearrange our comments and show them in their descending order.
The second method makes this job, even more, easier for those who are not comfortable with codes. The plugin called Simple Reverse Comments. With the help of this plugin, we do not have to edit any of our template files at all. Simply just download this plugin and activate it.
A most common problem with the WordPress sites is that we can’t easily rearrange comments order. Sure, we can use a custom menu, but also for some sites we have to rearrange the order of our comments. This code will show how to do it more easily.
This code above will find for a specific category (Don’t forget to get update line 5) and then do replace it on the top of all the other categories. This code has to be pasted
<?php $categories = get_terms('books_category'); for( $i=0; $i<sizeof($categories); $i++ ){ if ( $categories[$i]->name == 'New Publications' ) : $latest = array($categories[$i]); unset($categories[$i]); endif; } if( isset($latest) ) array_splice( $categories, 0, 0, $latest ); ?>
Ever since I started using the WordPress 4+ theme and then used custom post types for things like portfolio, service, FAQ, staff or sliders, I have gotten more questions from many questions. People asked me how to rearrange the order of comments. Unfortunately, how to do this in WordPress is not very obvious, and there are not many very easy and manageable methods.
In this following post, I’ve shown to you how you can change the order of your custom comments using this different method: changing the post date of our custom comments or using some nice awesome free a WordPress plugin called as “Post Type Order”.