如何在网格系统引导中使用wordpress循环?
我想显示一个带两列的条形行,其中包含wordpress循环内容(标题,绿色方块中的exrept)。每行都有白色和灰色背景的列,每行都像棋盘格一样反转如何在网格系统引导中使用wordpress循环?,wordpress,twitter-bootstrap,loops,grid,Wordpress,Twitter Bootstrap,Loops,Grid,我想显示一个带两列的条形行,其中包含wordpress循环内容(标题,绿色方块中的exrept)。每行都有白色和灰色背景的列,每行都像棋盘格一样反转 有关详细信息,请参见图片。编辑的答案 我相信这就是你要找的。这将遍历所有的帖子,然后按照草图的外观对它们进行排序 <div class='container'> <?php $args = array( 'post_type' => 'post' // Get only posts
有关详细信息,请参见图片。编辑的答案 我相信这就是你要找的。这将遍历所有的帖子,然后按照草图的外观对它们进行排序
<div class='container'>
<?php
$args = array(
'post_type' => 'post' // Get only posts
);
$the_query = new WP_Query ( $args ); // build query
$count = $the_query->post_count; // Check number of posts
<style>
.row:nth-child(even) .col-5:nth-child(even) { /* Select every even row and and even post */
background: #ddd;
}
.row:nth-child(odd) .col-5:nth-child(odd) { /* Select every odd row and odd post*/
background: #ddd;
}
</style>
<?php
while ( $the_query -> have_posts() ) : $the_query -> the_post();
$post_index = $the_query->current_post + 1; // $current_post = gets the post index in loop
if ( $post_index % 2 != 0 ) { // Open div if post is odd
echo '<div class="row" style="border: 2px solid red; padding: 20px; margin:30px;">';
}
if ( $post_index % 2 != 0) { // If post is odd then give one class
?>
<div class="col-xs-5 <?php echo "post_$post_index" ?>" style="border: 1px solid green;">
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</div>
<?php
} else {
?>
<div class="col-xs-5 col-xs-push-2 <?php echo "post_$post_index" ?>" style="border: 1px solid green;">
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</div>
<?php } // End if ( $post_index % 2 != 0)
if ( $post_index % 2 == 0 ) { // Close div if post is even
echo "</div>";
}
endwhile;
wp_reset_postdata();
?>
</div>
<!-- /.container -->