How to Create a Comments Central Page Template in WordPress – WPSaviour

By WP Saviour •  Updated: 02/25/21 •  3 min read

One approach to enhance customer engagements is to reward their feedback by showcasing them in your web site. Moreover, you can too function the highest commenters as nicely, linking again to their web site within the course of. Right here we’ll create a devoted Web page Template to show these feedback and commenters in a single place.

In brief, this tutorial will train you find out how to:

  1. create a Web page Template,
  2. use SQL queries in your code to fetch feedback with various parameters,
  3. create a piece of the Web page that’s solely viewable by Admin,
  4. add assist for a comment-related plugin.

Making a Web page Template

The best approach to create a Web page Template is to open the web page.php file in your theme, which can roughly appear like this:

  
    
    

The SQL question asks for all authorised feedback sorted by date (newest first). $max is the place we set the quantity of feedback to get, 7 in our case. The output of the code above will likely be an unordered checklist of latest feedback:

a7ud5-6509328

With a little bit CSS we will straighten that to look higher:

#cc-recent-comments li {
  width: 100%;
  float: left;
  list-style-type: none;
}

#cc-recent-comments li img {
  float: left;
  margin-top: -5px;
}

lexpu-4564353

$template determines how the precise textual content will likely be written; that is based mostly on the format made by WP Remark Remix, and you may observe that hyperlink to be taught extra on customizing it (search for ‘tokens’).

Subsequent is Latest Pingbacks / Trackbacks:

Latest Pingbacks / Trackbacks




The code above is similar to the one we now have for Latest Feedback, the one variations being that we’re now asking for feedback with ‘comment_type’ beneath ‘pingback’ / ‘trackback’, and the template is a bit completely different as nicely. Outcome:

pdlje-6114989

Right here’s the code for Prime Commenters:

Prime Commenters




Nothing too mind-blowing there. Do discover the cool get_avatar() operate, although, which will provide you with the Gravatar for anybody whose e-mail handle you specify. On this case, we fetch the avatar picture utilizing the commenter’s e-mail handle. With the CSS much like the one we now have for latest feedback, we will have this outcome:

#cc-top-commenters li {
  width: 100%;
  float: left;
  list-style-type: none;
}

#cc-top-commenters li img {
  float: left;
  margin-top: -5px;
}

yiajv-5972481

Final is Most Commented Posts:

Most Commented Posts




fwjet-4478469

And that’s it. Subsequent, we’ll add some further coolness by including some stuff that solely the admin can see.

Admin-only Data

To point out stuff just for the admins, we will use this code snippet from WPCandy:

   

Now on the Dashboard, we get a fast look of a web site’s whole, authorised, pending overview and spam feedback. Let’s replicate this for our Web page Template for simpler, admin-only entry:

Complete Feedback:

WP Saviour

I am a WordPress specialist. My mission is to help you create beautiful websites with ease!