我正在尝试创建一个包含两个 div 的滑块,然后关闭。现在我有一个计数器,如果帖子可以被两个整除,它将关闭并打开一个新的 div。不幸的是,它也在打开和关闭一个空的 div。这是我的代码:
<div id="brew-slider" class="global-width cycle-slideshow" data-cycle-fx="fade" data-cycle-timeout="0" data-cycle-slides="> div" data-cycle-pager=".cycle-pager" data-cycle-auto-height="container">
<?php
$args = array(
'post_type' => 'beer',
);
$beer_list = new WP_Query( $args );
$post_counter = 1;
if($beer_list->have_posts()){
?>
<div class="brew-slide group">
<?php
while($beer_list->have_posts()) {
$beer_list->the_post();
$hops = get_post_meta($post->ID, 'hops', true);
$url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
$abv = get_post_meta($post->ID, 'abv', true);
$ibu = get_post_meta($post->ID, 'ibu', true);
$availability = get_post_meta($post->ID, 'availability', true);
?>
<div class="col2-slide floatleft group">
<img src="<?=$url[0]?>" alt="<?php the_title(); ?>">
<div class="brew-content">
<h3 class="brew-title"><?php the_title(); ?></h3>
<?php the_tags(); ?>
<?php the_content();?>
<p><strong>Hops:</strong> <?=$hops?></p>
<h3 class="green-box">ABV: <?=$abv?>%</h3>
<h3 class="green-box">IBU's: <?=$ibv?></h3>
<h4 class="green-box"><?=$availability?></h4>
</div>
</div>
<?php
if($post_counter % 2 == 0) {echo '</div><div class="brew-slide group">';}
$post_counter++;
}//End While Loop
?>
</div>
<?php
}//End of If
else {
?>
<p>Currently no beers listed</p>
<?php
}
wp_reset_postdata();
?>
</div>