Skip to content

Instantly share code, notes, and snippets.

@yokotak0527
Created May 30, 2012 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yokotak0527/2834564 to your computer and use it in GitHub Desktop.
Save yokotak0527/2834564 to your computer and use it in GitHub Desktop.
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