这成功了
<?php
$gallery = get_post_meta($post->ID, 'gallery', true);
preg_match('/\[gallery.*ids=.(.*).\]/', $gallery, $ids);
$images_id = explode(",", $ids[1]);
if ($images_id[0] != "") {
if (is_array($images_id) || is_object($images_id)) {
foreach ($images_id as $image) {
$image_url = wp_get_attachment_image_src($image, 'banner');
?>
<a href="<?php echo $image_url[0]; ?>">
<?php echo wp_get_attachment_image($image, 'destinatoin', 'false', array("class" => "img-responsive")); ?>
</a>
<?php }
}
} ?>
应该做的是
preg_match('/\[gallery.*ids=.(.*).\]/', $gallery, $ids);
$images_id = explode(",", $ids[1]);
这将创建一个 id 数组,然后我可以循环遍历图像
foreach ($images_id as $image) {
$image_url = wp_get_attachment_image_src($image, 'banner');
?>
<a href="<?php echo $image_url[0]; ?>">
<?php echo wp_get_attachment_image($image, 'destinatoin', 'false', array("class" => "img-responsive")); ?>
</a>
<?php }