如何将WordPress帖子水平显示为3列?

Dar*_*son 6 css php wordpress twitter-bootstrap

我正在将使用Bootstrap构建的主题集成到WordPress中,现在我面临着水平而不是垂直显示帖子的挑战.该设计使用3列.

在这个网站上发布的两个专栏的解决方案(http://perishablepress.com/two-column-horizo​​ntal-sequence-wordpress-post-order/)很有帮助,但是当与3列一起使用时,它会重复发布先前显示的帖子.

这是我的代码:

    <div class="row">

    <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) : $wp_query->next_post(); else : the_post(); ?>

    <div class="col-sm-4">
    <img src="<?php the_field('home_page_slider_image'); ?>" class="img-responsive" >
    <h3><?php the_field( 'description' ); ?></h3>

    </div>

    <?php endif; endwhile; else: ?>
    <div>Alternate content</div>
    <?php endif; ?>

    <?php $i = 0; rewind_posts(); ?>

    <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) !== 0) : $wp_query->next_post(); else : the_post(); ?>

    <div class="col-sm-4">
    <img src="<?php the_field('home_page_slider_image'); ?>" class="img-responsive" >
    <h3><?php the_field( 'description' ); ?></h3>
    </div>

    <?php endif; endwhile; else: ?>
    <div>Alternate content</div>
    <?php endif; ?>


    <?php $i = 0; rewind_posts(); ?>

    <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) !== 0) : $wp_query->next_post(); else : the_post(); ?>

    <div class="col-sm-4">
    <img src="<?php the_field('home_page_slider_image'); ?>" class="img-responsive" >
    <h3><?php the_field( 'description' ); ?></h3>
    </div>

    <?php endif; endwhile; else: ?>
    <div>Alternate content</div>
    <?php endif; ?>



    </div>
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

谢谢.

jog*_*_pi 2

看看这个例子,它的工作方式就像你想要的那样,并根据这个例子安排你的代码。

$i = 1;
echo "<div class='row'>\n";
while( $i <= 10 ){

    echo "  <div class='col-lg-4'></div>\n";
    if( $i % 3 == 0 ) { echo "</div>\n<div class='row'>\n"; }

    $i++;
}
echo "</div>\n";
Run Code Online (Sandbox Code Playgroud)

http://codepad.org/Qesw28Cw