[英]Wordpress Category Sidebar
In the word press admin panel there is a category selection 'helper panel' which I am trying to recreate. 在单词新闻管理面板中,有一个类别选择“帮助面板”,我正在尝试重新创建。 However I can't find the code for it, could someone point me in the right direction please?
但是我找不到它的代码,有人可以向我指出正确的方向吗?
The actual Category Box that is created by Wordpress is not typically used by Plugins that utilize a Custom UI. 使用自定义UI的插件通常不使用Wordpress创建的实际类别框。 However, you can mimic its behavior, and you were most certainly on the right track with get_categories().
但是,您可以模仿它的行为,并且肯定可以使用get_categories()使其步入正确的轨道。 If you want to grab ALL categories, not just the ones with a post count, you need to call it like so:
如果要获取所有类别,而不仅仅是具有帖子数的类别,则需要这样调用:
<?php
$args = array(
'type' => 'post',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0, //<--IMPORTANT!!
'hierarchical' => 1,
'taxonomy' => 'category',
'pad_counts' => false );
$categories = get_categories($args);
?>
'hide_empty' is what you were missing. 'hide_empty'是您所缺少的。 Once you want to create your checkboxes, you would do something like this:
一旦要创建复选框,您将执行以下操作:
<form action="action.php" method="POST">
<?php
foreach($categories as $cat)
{
echo '<input type="checkbox" name="categories[]" value="'.$cat->cat_ID.'" />';
echo '<label>'$cat->name.'</label><br/>';
}
?>
<input type="text" name="user_input" value="" />
</form>
You can style the checkboxes however you like using a custom stylesheet , or you can apply the same tags and classes that the standard one uses, which will ensure that the existing Wordpress Admin Stylesheet styles everything accordingly. 您可以根据需要使用自定义样式表设置复选框的样式 ,也可以应用标准样式表使用的相同标签和类,这将确保现有的Wordpress Admin样式表相应地设置所有样式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.