试试这个
function image_thingy($atts) {
// Merge attribtes from shortcode with defaults
extract(shortcode_atts(array(
\'id\' => 1,
), $atts));
// Extract id\'s from shortcode attributes and convert into an array
$ids = explode(\',\',$atts[\'id\']);
$output = \'\'; // Variable that holds the shortcode output, at the end this will be returned
// Loop through ids and fetch urls, and add a comma with a blank space
foreach($ids as $id){
$output .= wp_get_attachment_url($id). \', \';
}
// remove comma and blank space from the end of $output, and finally return $output
return rtrim($output,\', \');
}
add_shortcode(\'imagez\', \'image_thingy\');
以下代码将URL包装在
<img>
标签:
function image_thingy($atts) {
extract(shortcode_atts(array(
\'id\' => 1,
), $atts));
$ids = explode(\',\',$atts[\'id\']);
$output = \'\';
foreach($ids as $id){
$output .= \'<img src="\'. wp_get_attachment_url($id) . \'"/> \';
}
return $output;
}
add_shortcode(\'imagez\', \'image_thingy\');