---
title: "根据别名查找分类属性"
author: "haimingyoung"
date: "2016-02-24T09:27:11Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2016-02-24T09:27:11Z"
id: 2278401
url: "https://haimingyoung.iteye.com/blog/2278401"
---

```
/**
 * 根据别名查找分类属性
 * @param type $slug
 * @param type $type
 * @return type
 */
function getCategoryProperty($slug,$type){
   
    $property = null;
    $catname = get_category_by_slug($slug);
   
    if($type == 'name'){
        $property = $catname->name;
    }
   
    if($type == 'slug'){
        $property = $catname->slug;
    }
   
    if($type == 'id'){
        $property = $catname->cat_ID;
    }
   
    if($type == 'parent'){
        $property = $catname->parent;
    }
   
    if($type == 'link'){
        $property = get_category_link($catname->cat_ID);
    }
   
    return $property;
}
```