function show_categories($atts, $content) { extract( shortcode_atts( array('taxonomy' => 'ad_cat'), $atts ) ); $cats = get_categories(array('taxonomy' => $taxonomy,'hide_empty' => 0, 'hierarchical' => 0, 'parent' => 0)); return show_categories_level($cats, '', '', $taxonomy); } function show_categories_level($cats, $names, $ids,$taxonomy) { $res = '<ol>'; foreach ($cats as $cat) { if($names)$n = "$names, $cat->name"; else $n = $cat->name; if($ids)$i = "$ids, $cat->term_id"; else $i = $cat->term_id; $res = $res."<li>$n : $i</li>"; $kittens = get_categories(array('taxonomy' => $taxonomy,'hide_empty' => 0, 'hierarchical' => 0, 'parent' =>$cat->term_id)); if($kittens) { $res .= ("<li>".show_categories_level($kittens, $n, $i, $taxonomy)."</li>"); } } return $res."</ol>"; } add_shortcode('show-categories', 'show_categories');
There are currently 1 users browsing this thread. (0 members and 1 guests)