简体   繁体   English

WordPress的类别侧边栏

[英]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.

相关问题 获取类别小部件的Wordpress侧栏中的类别链接 - get category link in Category Widget Wordpress sidebar 向 wordpress 中的类别存档页面添加侧边栏 - add a sidebar to the Category archive pages in wordpress 特定帖子类别的Wordpress更改侧栏 - Wordpress change sidebar for specific post category 多个类别的WordPress帖子-不同类别的侧边栏 - WordPress posts in multiple categories - different sidebar depending on category 从产品类别页面删除边栏| WordPress的Woocommerce - Remove Sidebar from Product Category Page | Wordpress Woocommerce Wordpress编辑发布侧边栏子类别不正确 - Wordpress edit post sidebar sub-category out of place 如何在WordPress边栏中正确编码以仅显示类别中最近1个月的帖子 - How correct code in WordPress sidebar to show only posts from last 1 month from category 为什么wordpress dymanic_sidebar在锚文本的title属性中显示类别描述? - Why wordpress dymanic_sidebar shows category description in the title attribute of the anchor text? WordPress在侧边栏的“帖子子类别”下显示所有子类别和帖子 - Wordpress Display All Sub categorys + posts under Posts Child Category in Sidebar 仅在 wordpress 小部件侧边栏中显示基于所选父类别的 Woo Commerce 子类别 - Only display Woo Commerce sub-categories based on selected Parent Category in a wordpress widget sidebar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM