2016-01-21 71 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; ?>  
相关问题