根据别名查找分类属性

/**
 * 根据别名查找分类属性
 * @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;
}

猜你喜欢

转载自haimingyoung.iteye.com/blog/2278401