dua55014 2013-02-13 10:15
浏览 15
已采纳

WordPress:如何只显示一个类别

In my design I show the category of the post in the home page. The problem is when I add more that one category in a post. How can I make so that it will display only one category.

Example: I have 3 categories A, B and C. I add a post in categories A and B. In the home page is displayed ... Post title in category A, B. I want the output to be ... Post title in category A.

For the category I use get_the_category_list

  • 写回答

1条回答 默认 最新

  • drj14664 2013-02-13 11:02
    关注

    get_the_category() returns an array of all associated categories for the post. To echo out only the first category from the result set try something like:

    <?php
       $category = get_the_category(); 
       echo $category[0]->cat_name;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部