【发布时间】:2019-11-15 21:34:25
【问题描述】:
我正在使用Bootstrap,我有一个帖子列表,我想将每 2 个帖子换成一行。每个帖子都包裹在<div col>.上,您可以看到直播here。
我试过这个,但它在每个帖子中都包含一行:
<?php
$num = 0;
// Check if there are any posts to display
if ( have_posts() ) : ?>
<?php
// The Loop
while ( have_posts() ) : the_post();
if($num%2) {
echo "<div class='row' style='margin-bottom: 2.3em;''>";
}
?>
<div class="col-xs-12 col-sm-6 col-md-6">
<h2 class="category-encabezado">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Enlace a <?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
</h2>
<small>Hace
<?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ''; ?>
</small>
<div class="entry">
<p>
<?php the_excerpt(); ?>
</p>
<?php
$my_shortcode = get_field('audio-field');
echo do_shortcode( $my_shortcode );
?>
</div>
</div>
<?php
if($num %2) {
echo '</div>';
}
$num++
?>
<?php endwhile; // End Loop
?>
</div>
<?php
【问题讨论】:
-
你能给我们一个更好的代码风格吗?代码不是很清楚@Pedro Corchero Murga
-
为美化代码而更新。
-
试试这个 - 我不是 100% 肯定,但可能会工作 - 在检查添加的条件后不要增加 $num,而是在检查之前这样做。 '; } ?> 还有一个错字——你不见了;在代码中的 $num++ 之后。
标签: php html twitter-bootstrap