我正在构建一个主题,对于主题设置页面,我遵循了本教程:http://wp.tutsplus.com/tutorials/using-the-settings-api-part-1-create-a-theme-options-page/
我现在想要的是每个类别都有一个多复选框。这就是我应该拥有的:
$options[] = array(
"section" => "zzz",
"id" => HS_SHORTNAME . "_multicheckbox_inputs",
"title" => __( \'Multi-Checkbox\', \'hs_textdomain\' ),
"desc" => __( \'Some Description\', \'hs_textdomain\' ),
"type" => "multi-checkbox",
"std" => \'\',
"choices" => array( __(\'Category 1\',\'hs_textdomain\') . "|category1", __(\'Category 2\',\'hs_textdomain\') . "|category2", __(\'Category 3\',\'hs_textdomain\') . "|category3")
);
然而,我尝试了多种选择,但没有一种能提供与上面所示完全相同的结果。我认为答案很接近get\\u categories()函数,但运气不好。还尝试了:
function my_list_cats() {
$cats = get_categories();
foreach($cats as $cat) {
$catsArray[] = __(\'\' . $cat->cat_name . \'\',\'hs_textdomain\') . "|" . $cat->category_nicename . "";
}
echo implode(\', \', $catsArray);
}
然后:
"choices" => array(my_list_cats())
但运气不好。有人知道解决方案吗?非常感谢你
最合适的回答,由SO网友:Alvaro 整理而成
谢谢Michael的提示。我终于明白了。解决方案如下:
$options[] = array(
"section" => "zzz",
"id" => HS_SHORTNAME . "_multicheckbox_inputs",
"title" => __( \'Multi-Checkbox\', \'hs_textdomain\' ),
"desc" => __( \'Some Description\', \'hs_textdomain\' ),
"type" => "multi-checkbox",
"std" => \'\',
"choices" => my_list_cats()
);
和在函数中。php:
function my_list_cats() {
$cats = get_categories();
foreach($cats as $cat) {
$catsArray[] = __(\'\' . $cat->cat_name . \'\',\'hs_textdomain\') . "|" . $cat->category_nicename . "";
}
return $catsArray;
}
再次感谢!