如果我理解正确,下面将获得帖子并将其放入行中,每行3个帖子。可以通过调整$columns变量来调整行。你也可以调整CSS以适应,这只是为了让帖子浮动和可见,因为我没有很多拇指来测试。
<style>
#test, .row{overflow: hidden; margin-bottom: 22px;}
.post {float: left; width: 150px; height: 150px; margin-right:20px; background: pink;}
.post.last {margin-right: 0;}
.post img {max-width: 100%;}
</style>
<div id="test">
<?php
global $post;
$tmp_post = $post;
$columns = 3; //number of posts per row
$args = array( \'cat\'=>22,
\'numberposts\' => 9 );
$count = 1;
$posts = get_posts($args); if($posts): ?>
<div class="row">
<?php
foreach ($posts as $post) : setup_postdata($post);
$class = ( $count%$columns == 0 ) ? \'last\' : \'\'; ?>
<div class="post">
<a href="<?php the_permalink() ?>" rel="<?php _e("bookmark", "solostream"); ?>" title="<?php _e("Permanent Link to", "solostream"); ?> <?php the_title(); ?>"><?php the_post_thumbnail( \'homepage-thumb\' ); ?>
<br/><?php the_title(); ?><br/>
<?php if(function_exists(\'the_field\')) the_field(\'price\'); ?>
</a>
</div><!--.post-->
<?php
if ( $count%$columns == 0 ) { ?>
</div><!--.row-->
<?php if ($count < count($posts)) : ?> <div class="row"> <?php endif; ?>
<?php }
$count++;
endforeach; ?>
</div><!--.row-->
<?php endif;
$post = $tmp_post;
?>
</div><!--#test-->