I need to create something like wp_list_categories that show empty categories but only if they have categories that have There are categories that have the post. Anyone have any ideas?
Thanks
You probably but I tried to do it in an old way .
$ categories = get_categories (); // First Index All categories by the original ID, later $ cats_by_parent = array (); Forex Currency ($ categories as $ cat) {$ parent_id = $ cat- & gt; Category_parents; If (! Array_key_exists ($ parent_id, $ cats_by_parent)) {$ cats_by_parent [$ parent_id] = array (); } $ Cats_by_parent [$ parent_id] [] = $ Cat; } // Then create a hierarchical tree $ cat_tree = array (); Function add_cats_to_bag (& amp; $ child_bag, & amp; $ children) {global $ cats_by_parent; Foreign Currency ($ child_cat as $ children) {$ child_id = $ child_cat-> Cat_ID; If (array_key_exists ($ child_id, $ cats_by_parent)) {$ child_cat- & gt; Children = array (); Add_cats_to_bag ($ child_cat-> kids, $ cats_by_parent [$ child_id]); } $ Child_bag [$ child_id] = $ child_cat; }} Add_cats_to_bag ($ cat_tree, $ cats_by_parent [0]); // With this actual tree, this recursive function can check the cats that you need the function_chander_v_ship (& amp; $ children) {$ has_child_with_posts = false; Foreign Currency ($ children_cat as $ children) {$ has_grandchildren_with_posts = false; If (isset ($ child_cat-> Kids)) // Here is our recursive call, so we do not leave any subsets if (has_children_with_posts ($ child_cat-> children)) {$ has_grandchildren_with_posts = true; }} If (0 category_count)) {$ has_child_with_posts = true; } And if ($ has_grandchildren_with_posts) {// This is a category in which there are no posts, but there are children who are $ $ child- gt; & Gt; Is_empty_with_children = true; Var_dump ($ child_cat- & gt; name); }} Return $ has_child_with_posts; } Has_children_with_posts ($ cat_tree);
Comments
Post a Comment