/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Restituisce una lista (UL/LI) delle categorie * @params $selected_cats Array delle categorie selezionate * * @return HTML */ function get_categories_checkboxes( $selected_cats = null ) { $all_categories = get_categories(); $o = '<ul style="margin-left:12px">'; foreach($all_categories as $key => $cat) { if($cat->parent == "0") $o .= __show_category($cat, $selected_cats); } return $o . '</ul>'; } function __show_category($cat_object, $selected_cats = null) { $checked = ""; } $ou = '<li><label><input ' . $checked .' type="checkbox" name="cats[]" value="'. $cat_object->cat_ID .'" /> ' . $cat_object->cat_name . '</label>'; $childs = get_categories('parent=' . $cat_object->cat_ID); foreach($childs as $key => $cat) { $ou .= '<ul style="margin-left:12px">' . __show_category($cat, $selected_cats) . '</ul>'; } $ou .= '</li>'; return $ou; }