您可能找不到任何附加图像,因为这些图像未被视为“附加”,或者之前已附加到其他帖子。
使用此脚本,您可以直接在the_content()
对于所有附加的图像,然后创建另一个仅包含<img>
从文本的其余部分清除标记。
$post_content = $post->post_content;
$search_pattern = \'/<img.*?src="(.*?)"/i\';
// Run preg_match_all to grab all the images and save the results in $embedded_images
preg_match_all( $search_pattern, $post_content, $embedded_images );
// Check to see if we have at least 1 image
$embedded_images_count = count( $embedded_images[0] );
if ( $embedded_images_count > 0 ) {
// Now here you would do whatever you need to do with the images
// For this example the images are just displayed
for ( $i=0; $i < $embedded_images_count ; $i++ ) {
echo $embedded_images[0][$i].\'<br>\';
};
};