我试图在foreach循环中使用下面的结构来获得结果,在每两幅图像之后,它将重复整个结构。
我有一些可以使用的基本知识,例如计数器++;和%2,但不知道语法以及如何在代码中使用它。
<?php
function dt_attached($postid=0, $size=\'thumbnail\', $attributes=\'\', $linksize=\'full\', $count=-1) {
if ($postid<1) $postid = get_the_ID();
if ($images = get_children(array(
\'post_parent\' => $postid,
\'post_type\' => \'attachment\',
\'numberposts\' => $count,
\'post_mime_type\' => \'image\',)))
foreach($images as $image) {
$attachment=wp_get_attachment_image_src($image->ID, \'thumbnail\');
$small_image = wp_get_attachment_image_src($image->ID, \'midium\');
$big_image = wp_get_attachment_image_src($image->ID, \'full\');
?>
<div class="mainrow">
<div class="block">
<a href=\'<?php echo $big_image[0]; ?>\' class=\'cloud-zoom-gallery\' title=\'Thumbnail 1\' rel="useZoom: \'zoom1\', smallImage: \'<?php echo $small_image[0]; ?>\' ">
<img src="<?php echo $attachment[0]; ?>" <?php echo $attributes; ?> />
</a>
</div>
<!--[I want to get two images in mainrow]-->
<div class="block">
<a href=\'<?php echo $big_image[0]; ?>\' class=\'cloud-zoom-gallery\' title=\'Thumbnail 1\' rel="useZoom: \'zoom1\', smallImage: \'<?php echo $small_image[0]; ?>\' ">
<img src="<?php echo $attachment[0]; ?>" <?php echo $attributes; ?> />
</a>
</div>
</div>
<?php //the_attachment_link($image->ID, false, true, false); ?>
<?php }
}
?>
所以我想要的是,如果有两个以上的图像,它将重复整个html结构。非常感谢你的帮助