Skip to content

Instantly share code, notes, and snippets.

@lori
Created January 31, 2013 22:16
Show Gist options
  • Save lori/4687118 to your computer and use it in GitHub Desktop.
Save lori/4687118 to your computer and use it in GitHub Desktop.
Category menu with subcategories & shortcode
<?php
/**
* Category menu with subcategories
*/
function bd_subategories_list($parent_cat_id = 100, $list_title = 'Category Name') { // category ID & name
?>
<h3 class="widget-title"><?php echo $list_title ?></h3>
<ul class="xoxo">
<?php echo '<li><a href="' . get_category_link( $parent_cat_id ) . '">' . $list_title . '</a></li>'; ?>
<ul class="xoxo">
<?php
wp_list_categories( array(
'child_of' => $parent_cat_id,
'title_li' => ''
) );
?>
</ul>
</ul>
<?php }
// Shortcode
function bd_subategories_list_shortcode() {
return bd_subategories_list();
}
add_shortcode( 'subcategories-list', 'bd_subategories_list_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment