按照关键词 ‘‘文章中图片’’ 的文章
获取WordPress文章中图片的数量
要获取WordPress文章内的图片数量,你可以使用以下代码片段:
一、在你的主题文件(例如functions.php)中:
// 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', $