views:

360

answers:

2

Hi Guys,

How would I go about displaying all of a site’s categories in checkboxes in my options panel?

I can get a dropdown select menu to work, I just have no idea how to implement checkboxes.

Code Here from Net Tuts: http://net.tutsplus.com/tutorials/wordpress/how-to-create-a-better-wordpress-options-panel/

http://pastie.org/885320

Thanks in advance.

A: 

Hi there Keith!

Hmmm, checkboxes... i can give you a rough idea on how to display them, i haven't managed to have a go on this tutorial so im not quite sure how everything fits together (i'll have another crack at it tonight).

I presume you've got your array of categories set up, well the way to implement checkboxes is simple:

foreach($categories as $category) {

   //print out your checkboxes
   echo "<input type='checkbox' name='mychecky' value='$category['whatever value you need']' />";
}

Let me know how you get on, i've always been meaning to clean up my wordpress admin!

All the best :)

Rob
A: 

i want to write category id to input value. but it is blank. what i have to do for this problem?

my code :

    $categories = get_categories('orderby=name');  
$wp_cats = array();  
foreach ($categories as $category_list ) 
{  
      $wp_cats[$category_list->cat_ID] = $category_list->cat_name;  
}  

foreach ($wp_cats as $v) {
   echo "<input type='checkbox' name='mychecky' value='$category[cat_ID]' />";
   echo $v;
   echo '<br>';
}

i solved my problem with this code block

$categories=get_categories();   foreach($categories as $category) {     echo "<input type='checkbox' name='mychecky' value='$category->term_id' />";    echo $category->cat_name;
    echo '<br>';    }
burakco