Get posts in archive page

时间:2011-11-16 作者:Allen

我使用此代码在列中显示帖子。如何设置此部分(“cat=3&;numberposts=5&;offset=0”),以便存档页面自动从单击的类别中获取帖子?

<div id="column1">

<?php $posts = get_posts(\'cat=3&numberposts=5&offset=0\'); foreach ($posts as $post) : start_wp(); ?>
<?php static $count1 = 0; if ($count1 == "5") { 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><strong><?php the_title(); ?><strong><br>
<?php the_field(\'price\'); ?>
<div style="clear:both;"></div>
<?php $count2++; } ?>
<?php endforeach; ?>

</div>

    <div id="column2">

<?php $posts = get_posts(\'cat=3&numberposts=5&offset=5\'); foreach ($posts as $post) : start_wp(); ?>
<?php static $count2 = 0; if ($count2 == "5") { 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><strong><?php the_title(); ?><strong><br>
<?php the_field(\'price\'); ?>
<div style="clear:both;"></div>
<?php $count2++; } ?>
<?php endforeach; ?>
    </div>

1 个回复
最合适的回答,由SO网友:Tom J Nowell 整理而成

不使用数字3,而是通过执行以下操作获取当前类别:

$cat_ID = get_query_var(\'cat\');
$posts = get_posts(\'cat=\'.$cat_ID.\'&numberposts=5&offset=0\');

结束

相关推荐