【发布时间】:2015-06-26 04:36:29
【问题描述】:
这是关于从答案中过滤 WordPress 的本机图库输出:here
// Now you loop through each attachment
foreach ($attachments as $id => $attachment) {
// Fetch all data related to attachment
$img = wp_prepare_attachment_for_js($id);
// If you want a different size change 'large' to eg. 'medium'
$url = $img['sizes']['large']['url'];
$height = $img['sizes']['large']['height'];
$width = $img['sizes']['large']['width'];
$alt = $img['alt'];
// Store the caption
$caption = $img['caption'];
$output .= "<li>\n";
$output .= "<img src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"{$alt}\" />\n";
// Output the caption if it exists
if ($caption) {
$output .= "<div class=\"orbit-caption\">{$caption}</div>\n";
}
$output .= "</li>\n";
}
$output .= "</ul>\n";
$output .= "</div>\n";
return $output;
}
如果再次需要结果,是否有更有效的方法来重复 foreach 循环输出,而不是仅仅重复 foreach 循环?
(可以在 foreach 循环中使用不同的变量,但不确定破坏串联输出是否合乎逻辑。)
希望有洞察力的逻辑或方法。
【问题讨论】:
标签: php arrays wordpress loops foreach