In this article I will show you how the top commentators of your WordPress blogs can display without the use of additional plugins.
For the readers of your blog it can be a nice incentive to know that the top commentators are displayed and linked to the home page of your blog. Process of commenting for the reader is possibly more interesting and you get more comments on your articles.
The code for determining the Top Commentators
The following code can as a whole in the functions.php file to be copied:
This feature makes the first part (lines 1-24) is nothing more than to pick the top 5 commentators on the last 30-days from the database.
In the second part (lines 26 - 38) in turn, the output is then assembled. Here, a list item is ever top commentator <li> </ li> generated, the contents of a link and in brackets the number of comments follows. The link is to the website of the commentator and the link title and the link text will be filled with the name of the commentator.
In this example, the link is a "follow" link, but you can of course adjust the code and the link just click on "nofollow" set ( rel = "nofollow" ).
Brief explanation of the SQL statement in detail
SELECT (lines 6-9)
Selects be the number of comments, the names and website URLs of the commentators.
FROM (line 10 - 11)
As was to be expected, we refer to the comments table of WordPress.
WHERE (line 12 - 17)
The terms include the following:
- The e-mail address is not empty
- The comment was not written by the (admin) user with ID 1 (ID must be adapted)
- The comment is also one and not a Trackback or Pingback
- The comment has been approved
- The comment has been posted within the last 30 days
GROUP BY and ORDER BY and LIMIT (lines 18-23)
So by using the e-mail addresses of commentators COUNT () to determine the correct number of comments. Are sorted descending by the selected Datenätze only the number of comments and then ascending to the name. The last is only set to a total of 5 records are selected.
The code to display the Top Commentators
The following code can be placed anywhere in your WordPress theme. So if you want eg the list of top 3 commentators for the last 15-days show in the sidebar, you can add the following code example in the sidebar.php to insert.
1. echo get_top_commentators (15, 3);
The top commentators view, I think a useful thing to get more comments on his blog. However, one should decide whether it is advisable to use the "follow" links or not (keyword spam).
Furthermore, one can also vary the amount of time and not show as in the example the top commentators in the last 30 days, but as a reference only accept the last 7 days, so that new visitors to your blog have a good chance to appear in the list.