douxu2081 2016-12-17 18:06
浏览 43
已采纳

如何使用猫头鹰旋转木马在wordpress循环中制作这张照片

I need to create something like this in my picture, i want to do this with php, something like this

enter image description here

$count = 0;

while ( $query->have_posts() ) : $query->the_post(); ?>

  <div class="item">

  <?php if( $count == 1 ) { echo '<div class="col-sm-6">'; } ?>

  <?php echo '<div class="col-sm-6">'; ?>

    <img src="sample">

  <?php echo '</div>'; ?>

  <?php if( $count == 1 ) { echo '</div>'; } ?>

  </div>

<?php $count++; endwhile

with bootstrap like this :

<div class="owl-carousel">
  <div class="item">
    <div class="col-sm-6">
      <div class="col-sm-12">
        <img src="sample">
      </div>
      <div class="col-sm-12">
        <img src="sample">
      </div>
    </div>
    <div class="col-sm-6">
      <img src="sample">
    </div>
  </div>
</div>

my code is wrong, i know, i need an Idea, how to do this, thank you

  • 写回答

1条回答 默认 最新

  • dongxuan58311366668 2016-12-18 14:21
    关注

    You have to do this in 2 parts first you have to build an associative array which will contain all 12 images URL, then you can loop through that array to display the images

    1st part to built an array:

    $owl_array = [];
    $args = array(
        'post_type' => 'post',
        'post_status' => 'publish'
    );
    
    $query = new WP_Query($args);
    
    if (!empty($query->posts)) {
        foreach ($query->posts as $key => $post) {
            //custom logic to get the image URL
            $thumb_id = get_post_thumbnail_id($post->ID);
            $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail', true);
            $owl_array[++$key] = (!empty($thumb_url_array[0])) ? $thumb_url_array[0] : 'http://example.com/default-image.jpg'; //assiging each featured image url into owl_array
        }
    }
    //print_r($owl_array);
    

    2nd part to diplay owl carousel:

    <div class="owl-carousel">
        <?php for ($i = 1; $i <= count($owl_array); $i++) { ?>
            <div class="item">
                <div class="col-sm-6">
                    <div class="col-sm-12 1">
                        <img src="<?php echo $owl_array[$i]; ?>">
                    </div>
                    <div class="col-sm-12 2">
                        <?php
                        $i++; //increment the counter
                        ?>
                        <img src="<?php echo $owl_array[$i]; ?>">
                    </div>
                </div>
                <div class="col-sm-6 3">
                    <?php
                    $i++; //increment the counter
                    ?>
                    <img src="<?php echo $owl_array[$i]; ?>">
                </div>
            </div>
        <?php } ?>
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序