我正在尝试使用以下方法在3列2行中随机显示6篇WordPress帖子:
<?php $the_query = new WP_Query("showposts=6&cat=1&orderby=rand");?>
例如,
<div class="row-fluid">
<div class="span4">
Random Post 1
</div>
<div class="span4">
Random Post 2
</div>
<div class="span4">
Random Post 3
</div>
</div>
<div class="row-fluid">
<div class="span4">
Random Post 4
</div>
<div class="span4">
Random Post 5
</div>
<div class="span4">
Random Post 6
</div>
</div>
我正在使用WP引导。任何帮助都将不胜感激。
最合适的回答,由SO网友:EssamSoft 整理而成
<?php
$the_query = new WP_Query("showposts=6&cat=1&orderby=rand");
while ( $the_query ->have_posts() ) {$the_query ->the_post(); $i++;
if ($i == 1){echo "<div class=row-fluid>";}
?>
<div class="span4">
Random Post <?php echo $i ; ?>
</div>
<?php
if ($i == 3){echo "</div><div class=row-fluid>";}
if ($i == 6){echo "</div>";$i=0;}
}
wp_reset_postdata();
?>