我试图在每篇文章后输出一组图像,但我只能输出一个。
add_filter( \'the_content\', \'image_posts\' );
function image_posts( $content ) {
global $post;
if ( ! $post instanceof WP_Post ) {
return $content;
}
$all_images = get_images(); // array of images
switch ( $post->post_type ) {
case \'page\':
// return $content; // this only return content
foreach ($all_images as $image){
echo \'<img src="\'.$image.\'" />\';
}
// return $content; // this returns all images on top of the content
default:
return $content;
}
}
如果我将循环修改为:foreach ($all_images as $image){
return content . \'<img src="\'.$image.\'" />\';
}
我只得到一张图片的内容。如何在内容之后输出所有图像?