首页 > 解决方案 > 无法在页面上显示自定义帖子类型类别

问题描述

我有一个名为“case_studies”的自定义帖子类型,它有 3 个类别:“seo”、“website-design”和“facebook-advertising”。

我在主页上有几个帖子,对于每个帖子,我想输出帖子的类别。

例如,最新的帖子有“seo”和“facebook-advertising”的类别,我希望它显示在页面中。

我试过 get_the_terms(); 功能,但我认为我使用不正确。

这是页面的代码:

<div class="container">
<!--
<div class="category_container">
    <p class="category_item" id="all">All</p>
    <p class="category_item" id="website">Websites</p>
    <p class="category_item" id="facebook">Facebook Ads</p>
    <p class="category_item" id="seo">SEO</p>
</div>
-->
<div class="row d-flex">
        <?php

           $args1 = array( 'post_type' => array('case_studies'), 'order' => 'DESC', 'posts_per_page' => 30, 'orderby' => 'date' );
           $loop = new WP_Query( $args1 );

           while ( $loop->have_posts() ) { 

           $loop->the_post();

           $feat_image = wp_get_attachment_url( get_post_thumbnail_id($loop->ID));  

        ?>
        <div class="col-sm-4">
             <div class="case-study-content">
                    <a href="<?php the_permalink() ?>" class="blog_blocks">
                        <div class="b_image">
                            <img src="<?php echo get_the_post_thumbnail_url(); ?>"/>
                        </div>
                        <div class="b_h_sec">
                        <h2><?php the_title(); ?></h2>
                        <p><?php echo wp_strip_all_tags( get_the_excerpt(), true ); ?></p>
                        <span class="r_m">Read More</span>
                        </div>
                    </a>
             </div>
        </div>

        <?php } ?>

        <?php wp_reset_postdata(); ?>
</div>
 </div>

这是输出现在的样子以及我希望在哪里显示类别。

在此处输入图像描述

标签: wordpress

解决方案


推荐阅读