Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Created July 11, 2012 14:02
Show Gist options
  • Save s-hiroshi/3090551 to your computer and use it in GitHub Desktop.
Save s-hiroshi/3090551 to your computer and use it in GitHub Desktop.
WordPress > snippet > get child category id
<?php
if (is_category('example') || in_category('example')) {
if (!is_front_page()) {
$cat = get_category_by_slug('example');
$cat_id = intval($cat->cat_ID);
$url = get_category_link($cat_id);
$name = $cat->name;
?>
<h2><a href="<?php echo esc_url($url); ?>"><?php echo esc_html($name); ?></a></h2>
<ul>
<?php wp_list_categories('child_of=' . $cat_id . '&hide_empty=0&title_li=&show_count=0'); ?>
</ul>
<?php
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment