【发布时间】:2015-11-20 14:25:58
【问题描述】:
我正在使用此代码显示相关帖子:
$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 5, 'post__not_in' => array($post->ID) ) );
?><h2> More from this category:</h2> <ul class="related-posts"> <?php
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
<li class="pov">
<div class="ex-s1">
<a href="<?php the_permalink();?>">
<?php the_post_thumbnail(array(356, 220)); ?>
</a>
</div>
<div class="ex-n1">
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</div>
<div class="ex-t1">
<?php echo get_excerpt(250);?>
</div>
</li>
<?php }
wp_reset_postdata(); ?>
</ul>
它有一个小问题。假设我们有 post1 和 post2。它们属于类别 1 和类别 2。如何在显示当前查看的 post1 的相关帖子的单个页面上仅获取 category1 的帖子而不是 cat2 的帖子?
谢谢!
【问题讨论】: