1. there are two main types of articles in the album category of the website, one is the native album function of WordPress, the other is a common article, and an image is inserted in the article; the requirement in this article is to count the total number of images in the text. For the demonstration effect, see loosky. netarchivescategoryalbum. 2. solution to get Article Images
1. there are two main types of articles in the album category of the website, one is the native album function of WordPress, the other is a common article, and an image is inserted in the article; the requirement in this article is to count the total number of images in the text. For details about the demo, see http://loosky.net/archives/category/album. 2. solution to get Article Images
1. Requirements
There are two main types of articles in the album category of the small site: one is the native album function of WordPress, and the other is a common article with an image inserted in the article; the requirement in this article is to count the total number of images in the text.
For details about the demo, see http://loosky.net/archives/category/album.
2. Solution: function for getting the number of article Images
Put the post_img_number function in functions. php.
Function post_img_number () {global $ post, $ posts; ob_start (); ob_end_clean (); // use do_encode code ($ post-> post_content) to process the photo album statistics $ output = preg_match_all ('// I', do_coding code ($ post-> post_content), $ matches ); $ cnt = count ($ matches [1]); return $ cnt ;}
Note: The biggest improvement of this function is to call the WordPress article content by using do_postal code ($ post-> post_content) instead of using $ post-> post_content, this solution prevents Statistics on images when the native album function is used.
Call a function
The call method is as follows:
Original article address: WordPress obtains the number of images in the article (album). Thank you for sharing it with the original author.