Display method of WordPress annual monthly article ranking

Source: Internet
Author: User
Tags php file time limit

Display of monthly article rankings


1. Add the following code to the functions. php file of your topic.

The code is as follows: Copy code

Function most_comm_posts ($ days = 7, $ nums = 10) {// The time limit value of the $ days parameter, in the unit of 'day'. The default value is 7 days; $ nums indicates the number of articles to be displayed.
Global $ wpdb;
$ Today = date ("Y-m-d H: I: s"); // Obtain the current date and time.
$ Daysago = date ("Y-m-d H: I: s", strtotime ($ today)-($ days * 24*60*60 )); // Today-$ days
$ Result = $ wpdb-> get_results ("SELECT comment_count, ID, post_title, post_date FROM $ wpdb-> posts WHERE post_date BETWEEN '$ daysago' AND '$ today' order by comment_count desc limit 0, $ nums ");
$ Output = '';
If (empty ($ result )){
$ Output = '<li> None data. </li> ';
} Else {
Foreach ($ result as $ topten ){
$ Postid = $ topten-> ID;
$ Title = $ topten-> post_title;
$ Commentcount = $ topten-> comment_count;
If ($ commentcount! = 0 ){
$ Output. = '<li> <a href = "'. get_permalink ($ postid ). '"title = "'. $ title. '"> '. $ title. '</a> ('. $ commentcount. ') </li> ';
   }
  }
 }
Echo $ output;
}

2. Call the sidebar. php file in the sidebar. The code is as follows:

The code is as follows: Copy code
<H3> most recent articles <Ul>
<? Php if (function_exists ('most _ comm_posts ') most_comm_posts (30, 10);?>
</Ul>

 

Garden Friendly reminder: parameter 1 after the most_comm_posts function is calculated by day. You can customize the number of days, such as 30. Parameter 2 indicates the number of entries displayed in the document. To display 10 entries, enter 10.

For example, most_comm_posts (30, 10) indicates that 10 articles with the most comments are displayed within 30 days.


How to use the annual monthly blog article statistics plug-in

How to use the wp-stats plug-in
1. Download the wp-stats plug-in at the bottom of this article.

2. Decompress the package and upload the wp-stats.php to the wordpress root directory. Remember that it is the root directory. Go to yourdomain.com/wp-stats.php to view the statistical results of your blog.

3. After obtaining this statistical result, you can copy it to the article you want to publish.

4. If you want to display the rankings of previous years, you just need to find 2010 in the wp-stats.php and replace it with the year you want.

5. To delete this plug-in after use, you just need to delete the wp-stats.php document you uploaded in the root directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.