开发者

List categories with checkbox in Wordpress Options?

How would I display 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-cr开发者_开发百科eate-a-better-wordpress-options-panel/

http://pastie.org/885320


You can use wp_terms_checklist function (http://codex.wordpress.org/Function_Reference/wp_terms_checklist)


I want to write category id to input value but it is blank. What must I do to fix 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>';    }


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜