Skip to content

Instantly share code, notes, and snippets.

@kamichimo
Created February 13, 2015 07:14
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 kamichimo/a42232e52cfe69378837 to your computer and use it in GitHub Desktop.
Save kamichimo/a42232e52cfe69378837 to your computer and use it in GitHub Desktop.
カテゴリー一覧で孫カテゴリーは表示しない
$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