2

我将如何在选项面板的复选框中显示网站的所有类别?

我可以让一个下拉选择菜单工作,我只是不知道如何实现复选框。

来自 Net Tuts 的代码:http: //net.tutsplus.com/tutorials/wordpress/how-to-create-a-better-wordpress-options-panel/

http://pastie.org/885320

提前致谢。

4

3 回答 3

2

我想将类别 ID 写入输入值。但它是空白的。我必须为这个问题做些什么?

我的代码:

    $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>';
}

我用这个代码块解决了我的问题

$categories=get_categories();   foreach($categories as $category) {     echo "<input type='checkbox' name='mychecky' value='$category->term_id' />";    echo $category->cat_name;
    echo '<br>';    }
于 2010-04-30T23:47:13.773 回答
2

您可以使用 wp_terms_checklist 函数(http://codex.wordpress.org/Function_Reference/wp_terms_checklist

于 2012-10-10T14:57:40.097 回答
0

嗯,复选框......我可以给你一个关于如何显示它们的粗略想法,我还没有设法继续这个教程所以我不太确定所有东西是如何组合在一起的(我今晚会再试一次)。

我想您已经设置了类别数组,实现复选框的方法很简单:

foreach($categories as $category) {

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

让我知道你过得怎么样,我一直想清理我的 wordpress 管理员!

一切顺利 :)

于 2010-04-05T12:57:59.110 回答