dongni8969 2013-04-10 11:03
浏览 38

PHP中同一循环内的不同循环计数条件?

intricate grid layout

I'm currently trying to wrap the first 2 posts in a div with the video and then output the remaining posts with a div wrapped around every 3 posts, as per image.

the line

if( $wp_query->current_post < 2 ): 

i've also tried with

if($count < 2)

heres a condensed version of what i have so far: Any suggesttions would be really appreciated.

<div class="row-fluid">
    <div class="span8">
        <video></video>
    </div>
    <?php $count = 1; ?>
    <?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>
    <?php if( $wp_query->current_post < 2 ):?>
    <div class="span4">
                   // content
    </div>
    <?php if($count % 2 == 0) {
        echo '</div><div class="row-fluid">';
    }?>

    <?php else: ?>

    <div class="span4">
        //content
    </div>
    <?php if($count % 3 == 0) {
        echo '</div><div class="row-fluid">';
    }?>
    <?php $count++;?>
    <?php endif; ?>
    <?php endwhile; ?>
    <?php echo '</div>'; ?>
</div>
<?php else : ?>
<article>default wp stuff</article>
<?php endif; ?>
  • 写回答

1条回答 默认 最新

  • dp518158 2013-04-10 11:18
    关注

    I think it's an easier solution to just echo all your content and use css (float: left) to position the content properly.

    <div style="width: 900px;">
      <div style="float: left; width: 600px; height: 400px;">
          some content
      </div>
      <?php foreach($post_list as $post_item): ?>
        <div style="float: left; width: 300px; height: 200px;">
          <?= $post->getContent(); ?> or what ever you use
        </div>
      <?php endforeach; ?>
      <br style="clear: left; display: none;" />
    </div>
    

    Note that I'm not that experienced with CSS but I hope this can point you in the right direction.

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向