wordpress主题函数 get_the_category() 详解运用
申明
猎取与查询参数相匹配的种别对象
用法
<?php get_the_category( $id ) ?>
参数
id
(整数) (可选) 文章编号
默许: $post->ID (当前文章的编号)
例子
显现种别的图片
<?php
foreach((get_the_category()) as $category) {
echo '<img src="http://www.2zzt.com/images/' . $category->cat_ID . '.jpg" alt="' . $category->cat_name . '" />';
}
?>
显现第一个种别的称号
<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>
显现第一个种别的衔接
<?php
$category = get_the_category();
if($category[0]){
echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>';
}
?>
猎取指定文章编号的种别信息
<?php
global $post;
$categories = get_the_category($post->ID);
var_dump($categories);
?>
返回对象的成员
cat_ID
种别编号,存储在term_id字段
cat_name
种别称号,存储在name字段
category_nicename
别号,存储在slug字段
category_description
种别形貌,存储在description字段
category_parent
父种别编号,没有父类的为0,存储在parent字段
category_count
种别运用的数目,存储在count字段

评论列表