【发布时间】:2015-03-19 11:55:08
【问题描述】:
我正在尝试使用 Cycle2 在 Wordpress 中创建水平和垂直图像的图片组合,其中所有垂直(纵向)图像成对显示。以下代码有效,但它显示每个图像两次,一次作为当前图像,一次作为下一个图像。如果之前显示过图像,如何跳过该图像?谢谢!
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_parent' => $post->ID,
);
$attachments = get_posts( $args );
$length = count($attachments);
for($i = 0; $i < $length ; ++$i) {
$attachment = current($attachments);
$next_attachment = next($attachments);
$image_attributes = wp_get_attachment_image_src( $attachment->ID, 'large' );
$next_image_attributes = wp_get_attachment_image_src( $next_attachment->ID, 'large' );
$w = $image_attributes[1];
$h = $image_attributes[2];
$nw = $next_image_attributes[1];
$nh = $next_image_attributes[2];
if($h > $w & $nh > $nw) {
echo '<li>';
echo wp_get_attachment_image( $attachment->ID, 'large' );
echo wp_get_attachment_image( $next_attachment->ID, 'large' );
echo '</li>';
}
【问题讨论】:
标签: php wordpress loops jquery-cycle2