最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Get post category as a separate string and url

programmeradmin3浏览0评论

I need to figure out how to get post category as a string and link, both separate from each other. So the return would be something like:

Uncategorized

however both should be separate, because I need to put them in different parts of my markup.

I need to figure out how to get post category as a string and link, both separate from each other. So the return would be something like:

Uncategorized
http://link-to-the-category

however both should be separate, because I need to put them in different parts of my markup.

Share Improve this question asked Apr 22, 2013 at 11:41 IljaIlja 1533 silver badges14 bronze badges 1
  • review codex.wordpress/Function_Reference/get_the_category – Michael Commented Apr 22, 2013 at 12:53
Add a comment  | 

1 Answer 1

Reset to default 1

First you have to find the category ID, which can be done easily with the function get_the_category().

To get the slug, use: $catID = get_the_category(); $catSlug = $catID->slug.

To get the link: $catLink = get_category_link($catID).

发布评论

评论列表(0)

  1. 暂无评论