I want a list like in the pictue; witch is here - Posts->New->Select Categories
At the moment i have this
echo '<select name="pn-cats[]" size="8" style="width: 100%" multiple>';
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'category',
'pad_counts' => false
);
$categories = get_categories( $args );
foreach ($categories as $category) {
$option = '<option value="'.$category->cat_name.'">';
$option .= $category->cat_name;
$option .= ' ('.$category->count.')';
$option .= '</option>';
echo $option;
}
echo '</select>';
But i dont like my solution because the categories are not sorted like parent->child in the picture. I need a multi-selectable list.
Do you know any solution? wp_category_checklist don´t work because i need this list in a public page and not in the admin area.
Aucun commentaire:
Enregistrer un commentaire