【发布时间】:2023-03-23 05:22:01
【问题描述】:
我的投资组合页面中有这个相关帖子部分,我正在尝试使用“the_category”函数为每个帖子生成类别。在这种情况下,左侧帖子的类别为“照片、测试”,其余帖子的类别为“博客”。
该功能似乎工作正常,但正如您在附图中看到的那样,类别显示在标题上方。
我希望在“listing_meta”块中生成类别。 (在cmets旁边)
<div class="blog_content">
<div class="listing_meta">
<span>'. esc_html(get_the_time(get_option('date_format'))) .'</span>
<span class="blog_post_author">'. __('by', 'gt3_builder') .' <a href="'.get_author_posts_url( get_the_author_meta('ID')).'" class="text-capitalize">'.get_the_author_meta('display_name').'</a></span>
<span class="comments"><a href="' . get_comments_link() . '">'. get_comments_number(get_the_ID()) .'</a></span>
<span>'. the_category(', ') .'</span>
</div>
<div class="blog_post_title"><h2><a href="'. get_permalink() .'">' . get_the_title() . '</a></h2><div class="blog_post_format_label"></div></div>
</div>
有什么解决办法吗?
谢谢。
--------------已编辑--------- ----------
我尝试了函数“get_the_category”,但现在它以 ARRAY 形式返回所有类别,如图所示。
<div class="blog_content">
<div class="listing_meta">
<span>'. esc_html(get_the_time(get_option('date_format'))) .'</span>
<span class="blog_post_author">'. __('by', 'gt3_builder') .' <a href="'.get_author_posts_url( get_the_author_meta('ID')).'" class="text-capitalize">'.get_the_author_meta('display_name').'</a></span>
<span class="comments"><a href="' . get_comments_link() . '">'. get_comments_number(get_the_ID()) .'</a></span>
<span>'. get_the_category() .'</span>
</div>
<div class="blog_post_title"><h2><a href="'. get_permalink() .'">' . get_the_title() . '</a></h2><div class="blog_post_format_label"></div></div>
</div>
【问题讨论】:
标签: php wordpress function categories