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

标签 php css wordpress twitter-bootstrap

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

本站发布两栏的解决方案 ( http://perishablepress.com/two-column-horizontal-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>

如有任何帮助,我们将不胜感激。

谢谢。

最佳答案

看看这个例子,它的工作方式如你所愿,并根据这个例子安排你的代码。

$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";

http://codepad.org/Qesw28Cw

关于php - 如何将 WordPress 帖子水平显示为 3 列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21199556/

相关文章:

php - 使用 html、css 和 php 变量填充 pdf 模板

javascript - CSS:如何删除伪元素(之后,之前,......)?

javascript - 根据游戏 javascript 中的级别更改背景图像?

javascript - 无法让滚动动画与 jquery 一起使用

php - 哪个更快 : in_array or database queries?

php - Phpstorm未配置SQL方言

javascript - 在具有值的表单中使用图像作为选项

PHP MySQL 搜索建议

css - 菜单项恰好一个在另一个 wordpress 导航之上

css - Wordpress 侧边栏在 Internet Explorer 中消失到底部