Created
February 13, 2015 07:14
-
-
Save kamichimo/a42232e52cfe69378837 to your computer and use it in GitHub Desktop.
カテゴリー一覧で孫カテゴリーは表示しない
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
$cats = get_categories(); | |
$html = ''; | |
if ($cats): | |
$html .= '<ul>'; | |
foreach($cats as $cat){ | |
if($cat->parent == 0): | |
$html .= '<li><a href="'.get_category_link($cat->term_id).'">'.$cat->name.'</a>'; | |
$cats_child = get_categories('child_of=' . $cat->term_id); | |
if ($cats_child): | |
$html .= '<ul class="children">'; | |
foreach($cats_child as $child){ | |
$html .= '<li><a href="'.get_category_link($child->term_id).'">'.$child->name.'</a></li>'; | |
} | |
$html .= '</ul>'; | |
endif; | |
html .= '</li>'; | |
endif; | |
} | |
$html .= '</ul>'; | |
endif; | |
echo $html; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment