我使用以下代码在索引页上只显示拇指和标题;
<div id="column1">
<?php query_posts(\'cat=22&showposts=2\'); ?>
<?php $posts = get_posts(\'cat=22&numberposts=2&offset=0\'); foreach ($posts as $post) : start_wp(); ?>
<?php static $count1 = 0; if ($count1 == "2") { break; } else { ?>
<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\' ); ?></a>
<br><a style="color:#666;"><?php the_title(); ?></a><br>
<a style="color:#1C477E;"><?php the_field(\'price\'); ?></a>
<div style="clear:both;"></div>
<?php $count1++; } ?>
<?php endforeach; ?>
</div>
<div id="column2">
<?php query_posts(\'cat=22&showposts=2\'); ?>
<?php $posts = get_posts(\'cat=22&numberposts=2&offset=2\'); foreach ($posts as $post) : start_wp(); ?>
<?php static $count2 = 0; if ($count2 == "2") { break; } else { ?>
<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\' ); ?></a>
<br><a style="color:#666;"><?php the_title(); ?></a><br>
<a style="color:#1C477E;"><?php the_field(\'price\'); ?></a>
<div style="clear:both;"></div>
<?php $count2++; } ?>
<?php endforeach; ?>
</div>
当某个类别中的帖子少于或多于一列中描述的帖子数量时,就会出现问题。如果帖子较少,其他列仍为空,因此看起来很奇怪。我想以行而不是列的形式显示它们,这样帖子的数量就不会影响类别页面。