Created
July 11, 2012 14:02
-
-
Save s-hiroshi/3090551 to your computer and use it in GitHub Desktop.
WordPress > snippet > get child category id
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
<?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