2016-01-21 74 views
0

我的目標是檢查所有帖子,看它們是否在特定類別內,如果它們在該類別內,我想在那裏存儲圖像src放入數組$ backgroundimage [$ x]。然後稍後在滑塊中使用這些項目。目前代碼每次輸出相同的圖像。如何從特定類別的特色圖像中獲取圖像源並將其存儲在數組中

<?php if (have_posts()) : while (have_posts()) : the_post(); 
      if (in_category("Uncategorized")) : 
       if (has_post_thumbnail()) { 
        for ($x = 0; $x <= 3; $x++) {  

          $src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), full, false); 

          $backgroundimage[$x]=$src[0] ; 
               } ?> 


       <?php } endif; ?> 

<?php endwhile; else : 
    _e('Sorry, no posts matched your criteria.', 'textdomain'); 
endif; ?>  

後來我想動態插入$ backgroundimage [1]以及其餘的內嵌CSS。我目前正在獲得相同的圖像。

回答

0

這就是我最終能夠完成任務的方式。

<?php $x= 1 ?> 

<?php if (have_posts()) : while (have_posts()) : the_post(); 
      if (in_category("Uncategorized")) : 
       if (has_post_thumbnail()) { 


          $src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), full, false); 

          $backgroundimage[$x]=$src[0] ; 
              $x++; 


       } 
      endif; ?> 

<?php endwhile; else : 
    _e('Sorry, no posts matched your criteria.', 'textdomain'); 
endif; ?>  
相關問題