2016-12-07 64 views
0

WordPress用のカスタムテンプレートを作成しています。 1つの投稿に複数のおすすめ画像を追加してギャラリーやスライダーとして表示することができます。 すべてが最初の投稿で正常に動作します。最初に投稿された画像のみが表示されます

2つ以上の注目画像がある2番目の投稿を追加すると、表示されている画像が1つしかないと画像が表示されません。

は、誰もが私のコードを見直し、私が行方不明です何を教えてもらえます:

EDIT

<?php /* Template Name: Home v4 */ get_template_part('/template-parts/home4_header'); ?>    

    <section class="background-color"> 

     <?php query_posts('showposts=0'); ?>  
     <?php $i = 1; ?>    
     <?php if (have_posts()) : ?> 

     <?php while (have_posts()) : the_post(); ?> 
     <?php if(($i % 4) !== 0) { ?> 

     <!-- Fixed width banner --> 
     <div class="container">    
      <div class="containerBox"> 

       <!-- Multiple Featured Images Slider -->   
       <?php 
       if (class_exists('MultiPostThumbnails')) {        
       // Loops through each feature image and grabs thumbnail URL 

       $x=1; $image1_id; $image2_id; $image3_id; $image4_id; $image5_id; 

        while ($x<=5) { 
         $image_name = 'feature-image-'.$x; // sets image name as feature-image-1, feature-image-2 etc. 
         if (MultiPostThumbnails::has_post_thumbnail('post', $image_name)) { 
          $image_id = MultiPostThumbnails::get_post_thumbnail_id('post', $image_name, $post->ID); // use the MultiPostThumbnails to get the image ID 
          $image_thumb_url = wp_get_attachment_image_src($image_id,'small-thumb'); // define thumb src based on image ID 
          $image_feature_url = wp_get_attachment_image_src($image_id,'feature-image'); // define full size src based on image ID 
          $attr = array(
           'rel' => $image_thumb_url[0], // sets the url for the image thumbnails size 
           'src' => $image_feature_url[0], // sets the url for the full image size 
          );                      
          // Use wp_get_attachment_image instead of standard MultiPostThumbnails to be able to tweak attributes 
          $image = wp_get_attachment_image($image_id, 'feature-image', false, $attr);    
          //echo $image; 

          if ($x == 1) {$image1_id = $image_id;} 
          if ($x == 2) {$image2_id = $image_id;} 
          if ($x == 3) {$image3_id = $image_id;} 
          if ($x == 4) {$image4_id = $image_id;} 
          if ($x == 5) {$image5_id = $image_id;} 
         }       
         $x++; 
        }        

       }; // end if MultiPostThumbnails          


       if (!empty($image2_id)) { ?> 
       <div class="multi-thumb"> 
        <div id="ninja-slider"> 
         <div class="slider-inner"> 
          <ul>  
           <li> 
            <div class="slider"> 
            <?php the_post_thumbnail('full'); ?> 
            </div> 
           </li> 
           <li> 
            <div class="slider"> 
            <img src="<?php echo wp_get_attachment_image($image2_id, 'feature-image', false, $attr);?>"> 
            </div> 
           </li> 
           <?php if (!empty($image3_id)) { ?> 
           <li> 
            <div class="slider"> 
            <img src="<?php echo wp_get_attachment_image($image3_id, 'feature-image', false, $attr);?>"> 
            </div> 
           </li> 
           <?php } ?> 
           <?php if (!empty($image4_id)) { ?> 
           <li> 
            <div class="slider"> 
            <img src="<?php echo wp_get_attachment_image($image4_id, 'feature-image', false, $attr);?>"> 
            </div> 
           </li> 
           <?php } ?> 
           <?php if (!empty($image5_id)) { ?> 
           <li> 
            <div class="slider"> 
            <img src="<?php echo wp_get_attachment_image($image5_id, 'feature-image', false, $attr);?>"> 
            </div> 
           </li> 
           <?php } ?>  
          </ul> 
         <div class="fs-icon" title="Expand/Close"></div> 
         </div> 
        </div> 
       </div>  
       <?php 
       unset($image1_id, $image2_id, $image3_id, $image4_id, $image5_id, $image_name, $image, $image_thumb_url, $image_feature_url); 

       } else { the_post_thumbnail('full'); } ?> 
       <!-- End Multiple Featured Images Slider -->    
      </div> 

      <div class="post-area-category container-post-color bottom-padding"> 
       <div class="content-block w-clearfix"> 
        <div class="category"> 
         <h5><?php echo the_category();?></h5> 
        </div> 
        <h1 class="black mastheading-post-v3"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1> 
        <div class="date-block-v3 w-container"> 
         <div class="black mini-date"><?php echo get_the_date(); ?></div> 
         <img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/comment-icon.png' ?>"> 
         <div class="black mini-date"> 
          <?php 
          $comments_count = wp_count_comments(); 
          echo $comments_count->approved; 
          ?> 
         </div> 
         <img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/heart-icon.png' ?>"> 
         <div class="black mini-date">14</div> 
        </div> 
        <div class="black iltalica"><?php the_excerpt(); ?></div> 
        <a class="a8 cta-home-category w-button" href="<?php the_permalink(); ?>">continue reading</a> 
       </div> 
      </div> 
      <div class="space-4 background-color"></div>  
     </div> 
     <!-- Fixed width banner --> 

     <?php } elseif (($i % 4) == 0) { ?> 

      <!-- Full width banner --> 
      <div class="container-fluid">    
       <div class="containerBox"> 
        <div class="home-v3-full-banner"> 
         <?php the_post_thumbnail('full'); ?> 
        </div> 
       </div> 
      </div> 

      <div class="container post-area-category container-post-color bottom-padding"> 
      <div class="content-block w-clearfix"> 
       <div class="category"> 
        <h5><?php echo the_category();?></h5> 
       </div> 
       <h1 class="black mastheading-post-v3"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1> 
       <div class="date-block-v3 w-container"> 
        <div class="black mini-date"><?php echo get_the_date(); ?></div> 
        <img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/comment-icon.png' ?>"> 
        <div class="black mini-date"> 
         <?php 
          $comments_count = wp_count_comments(); 
          echo $comments_count->approved; 
          ?> 
        </div> 
        <img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/heart-icon.png' ?>"> 
        <div class="black mini-date">14</div> 
       </div> 
       <div class="black iltalica"><?php the_excerpt(); ?></div> 
       <a class="a8 cta-home-category w-button" href="<?php the_permalink(); ?>">continue reading</a> 
      </div> 
      </div> 
     </div> 
     <!-- End Full width banner --> 


     <?php } ?> 
     <?php $i++; ?> 
     <?php endwhile; else: ?> 

     <p>Sorry, no posts matched your criteria.</p> 

     <?php endif; ?> 
     <?php wp_reset_query(); ?> 

    </section> 
<?php get_footer(); ?> 
+0

完全なコードを投稿できますか?テンプレートページコードを意味します。私はあなたが$ i = 1で間違ったと思う。または$ x。私は確信しています。 – vel

+0

このページには@velコードが追加されています... – Barlet

+0

2枚目の画像を3枚追加しました。 – vel

答えて

0

このコードを試してみてください。テストされていません

 <?php query_posts('showposts=0'); ?>  

     <?php if (have_posts()) : ?> 

     <?php while (have_posts()) : the_post(); ?> 
     <?php $i = 1; ?> 
関連する問題