巫冰吧 关注:13贴子:384
  • 0回复贴,共1

WordPress获取文章中的图片个数

只看楼主收藏回复

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().'张图片' ?>


1楼2016-09-27 16:21回复