2

内部に 2 つの div があるスライダーを作成して閉じようとしています。現在、カウンターがあり、投稿が2で割り切れる場合は、新しい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>
4

2 に答える 2

0

ということで、いろいろ調べた結果、自力で入手することができました。助けようとしてくれたすべての人に感謝します。これが私がやったことに対する答えです。

                            <?php
                                $args = array(
                                    'post_type' => 'beer',
                                );
                                $beer_list = new WP_Query( $args );
                                if($beer_list->have_posts()){
                                ?>
                            <?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);
                                        if($beer_list->current_post%2 == 0) echo "\n".'<div class="brew-slide group">'."\n";
                                    ?>
                            <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($beer_list->current_post%2 == 1 || $beer_list->current_post == $beer_list->post_count-1) echo '</div>'."\n";
                                    }
                                ?>
                                <?php
                                }
                                else {
                                ?>
                                <p>Currently no beers listed</p>
                            <?php
                                }
                                wp_reset_postdata();
                            ?>
于 2013-11-07T22:19:17.507 に答える
0

$post_counterが偶数で、これが最後の投稿ではないかどうかを確認する必要があります。そのようです:

if($post_counter % 2 == 0 && $beer_list->have_posts()) 
  {echo '</div><div class="brew-slide group">';}
于 2013-11-04T17:14:43.283 に答える