获取帖子列表自定义帖子类型类别明智

问题描述 投票:0回答:1

我希望将所有帖子显示为自定义帖子类型的列表类别。例如:演示猫1 - 类别演示1的帖子 - 类别演示1的帖子 - 类别演示2的帖子 - 类别名称2的帖子

custom-post-type categories taxonomy
1个回答
0
投票
   <?php
    $args = array(
            'post_type' => 'post',
            'posts_per_page' => -1,  //show all posts
            'tax_query' => array(
                array(
                    'taxonomy' => 'category',
                    'field' => 'slug',
                    'terms' => $term->slug,
                )
            )

        );
    $posts = new WP_Query($args);

    if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post(); ?>

                <?php if(has_post_thumbnail()) { ?>
                        <?php the_post_thumbnail(); ?>
                <?php }
                /* no post image so show a default img */
                else { ?>
                       <img src="<?php bloginfo('template_url'); ?>/assets/img/default-img.png" alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>" width="110" height="110" />
                <?php } ?>

               <?php  echo get_the_title(); ?>

                    <?php the_excerpt(); ?>


    <?php endwhile; endif; ?>

https://wordimpress.com/loop-through-categories-and-display-posts-within/

© www.soinside.com 2019 - 2024. All rights reserved.