Add article count statistics for WordPress

Source: Internet
Author: User

When WordPress is editing logs in the background, there is a word count in the lower left corner of the editing box, but it is only displayed in the background. Can I add the word count statistics function in the front? After studying the program source file, we found that the Chinese version of WP background word count function is achieved through the wp-content \ ages directory zh_CN-word-count.js, that is, do not know how to call. I searched the internet and found two code provided by foreigners:
 
1. Add the following code to the topic's functions. php file:
 
Function count_words ($ str ){
$ Words = 0;
$ Str = eregi_replace ("+", "", $ str );
$ Array = explode ("", $ str );
For ($ I = 0; $ I <count ($ array); $ I ++)
{
If (eregi ("[0-9A-Za-z À-öø-limit]", $ array [$ I])
$ Words ++;
}
Return $ words;
}
 
In single. php, add:
 
Word count: <? Php echo count_words ($ post-> post_content);?>
 
Original
 
2. Add the following code to the functions. php file. This method is different from the above, and an estimated reading time is added:
 
// Custom functions
// START: Show word count
Function show_post_word_count (){
Ob_start ();
The_content ();
$ Content = ob_get_clean ();
Return sizeof (explode ("", $ content ));
}
// END: Show word count
// START: Estimated reading time
If (! Function_exists ('est _ read_time ')):
Function est_read_time ($ return = false ){
$ Wordcount = round (str_word_count (get_the_content (),-2 );
$ Minutes_fast = ceil ($ wordcount/250 );
$ Minutes_slow = ceil ($ wordcount/150 );
If ($ wordcount <= 150 ){
$ Output = _ ("<1 minute ");
} Else {
$ Output = sprintf (_ ("% s-% s minutes"), $ minutes_fast, $ minutes_slow );
}
Echo $ output;
}
Endif;
If (! Function_exists ('est _ the_content ')):
Function est_the_content ($ orig ){
// Prepend the reading time to the post content
Return est_read_time (true). "\ n". $ orig;
}
Endif;
// END: Estimated reading time
 
Similarly, in single. php, you want to add:
 
The following <? Php echo show_post_word_count ();?> Words shoshould take about <? Php echo est_read_time ();?> To read.
 
Original
 
Unfortunately, the above two methods are ineffective in Chinese Character statistics. They are only suitable for English-only websites. No articles related to Chinese Blog word count statistics have been found on the Internet.

Excerpted from zhiwubird

Related Article

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.