WordPress获取文章中的图片个数函数/* * 获取文章中的图片个数
if( !function_exists('get_post_images_number') ){ function get_post_images_number(){ global $post; $content = $post->post_content; preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $result, PREG_PATTERN_ORDER); return count($result[1]); }}
函数使用方法:
<?php echo get_post_images_number().'张图片' ?>
if( !function_exists('get_post_images_number') ){ function get_post_images_number(){ global $post; $content = $post->post_content; preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $result, PREG_PATTERN_ORDER); return count($result[1]); }}
函数使用方法:
<?php echo get_post_images_number().'张图片' ?>