Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
wordpressでエントリーのルートカテゴリーを取得する
//ex -> the_root_category(get_the_category(),"span");
function the_root_category($cat,$mode="li"){
$cat = get_root_category($cat);
$cnt = count($cat);
$_cat;
for($i = 0;$i<$cnt;$i++){
echo "<".$mode." class='catGroup catGroup".$i." ".$cat[$i]->slug."'>".$cat[$i]->name."</".$mode.">";
}
};
//ex -> get_root_category(get_the_category());
function get_root_category($cat){
$cnt = count($cat);
for($i = 0;$i<$cnt;$i++){
while($cat[$i]->parent) $cat[$i] = get_category($cat[$i]->parent);
}
return $cat;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.