在PHP中,函数只能返回一次它的值。返回值后,函数终止。
如果要返回多个值,必须使用数组。因此,您的代码可能如下所示:
function get_images() {
global $post; // you don\'t use $post in your code, so it\'s redundant
$size = \'medium\';
$attachments = get_children( array(
\'post_parent\' => get_the_ID(),
\'post_status\' => null, // ??
\'numberposts\' => -1, // you should use posts_per_page insted of numberposts
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\',
\'order\' => \'ASC\',
\'orderby\' => \'menu_order\'
) );
if (empty($attachments)) {
return \'\';
}
$images = array();
foreach ( $attachments as $id => $attachment ) {
$images[] = wp_get_attachment_image_src($attachment->ID, $size );
}
return $images;
}
附言,但这与WordPress无关。。。