Wordpress,获取ID';来自URL的多个类别的

Wordpress,获取ID';来自URL的多个类别的,wordpress,categories,Wordpress,Categories,我正在使用WordPress 2.8.4 我的问题是,如果我正在查看子类别(cat-slug-2,在本例中),是否有一个内置函数来获取其类别ID及其父类别ID 下面是一个示例URL,其中cat-slug-2是cat-slug-1 http://www.foo.com/category/cat-slug-1/cat-slug-2/也许是这样的 <?php $current_category = single_cat_title("", false); $category_ID

我正在使用WordPress 2.8.4

我的问题是,如果我正在查看子类别(
cat-slug-2
,在本例中),是否有一个内置函数来获取其类别ID及其父类别ID

下面是一个示例URL,其中
cat-slug-2
cat-slug-1


http://www.foo.com/category/cat-slug-1/cat-slug-2/

也许是这样的

<?php
    $current_category = single_cat_title("", false);
    $category_ID = $wpdb->get_var( "SELECT term_id FROM $wpdb->terms WHERE slug = '" . $current_category . "'" );
    echo(get_category_parents($category_ID, TRUE, ' &raquo; '));
?>

谢谢你的回答Manzabar,从你的代码中我可以修改它以得到我想要的

最终,我想要一个类别的parentId数组。我是这样做的:

$parents = get_category_parents($cat, false, '^%%^');
$parents = explode('^%%^', $parents);
$parentIDs = array();
foreach($parents as $parent){
    if (is_null($parent) || empty($parent)){
        continue;
    }
    $parentIDs[] = get_cat_ID($parent);
}
echo '<pre>';
print_r($parentIDs);
echo '</pre>';
$parents=get_category_parents($cat,false,^%%^');
$parents=分解(“^%%^”,$parents);
$parentId=array();
foreach($parents作为$parent){
如果(为null($parent)|为空($parent)){
持续
}
$parentId[]=获取猫的ID($parent);
}
回声';
打印(parentid);
回声';
请注意,$cat保存当前的类别ID