Created
May 30, 2012 08:36
-
-
Save yokotak0527/2834564 to your computer and use it in GitHub Desktop.
wordpressでエントリーのルートカテゴリーを取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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