如何在WordPress中显示当前单个帖子类别的自定义帖子类型的所有帖子?

时间:2018-01-25 03:46:10

标签: wordpress custom-post-type

我有自定义帖子类型,它有很多类别。当我打开这个自定义帖子类型帖子的单个帖子,然后在这个自定义单个帖子的底部,我想从这个帖子类别中显示8个帖子标题,图片等。

1 个答案:

答案 0 :(得分:0)

在主题的single.php中添加此代码。

$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 8, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
 <ul> 
        <li>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
            <?php the_content('Read the rest of this entry &raquo;'); ?>
			<?php the_post_thumbnail( 'thumbnail' ); ?> 
        </li>
    </ul>   
<?php }
wp_reset_postdata(); ?>

相关问题