有没有办法在文章编辑器中按父级划分类别?
在我的网站上,有许多类别的主题,例如:国家、系统、公司..,每个类别都包含多个子类别。 创建文章时,很难对其进行分类 有没有一种方法或代码来划分类别,以便可以将每个父母及其孩子放在一个小部件中
< img src="https://i.sstatic.net/YM1ap.png" alt="在此处输入图像描述">
On my site, there are many categories of topics such as: countries, system, company .. and each category contains a multiple sub-category.
When creating an article, it is difficult to categorize it
Is there a way or code to divide the categories, so that can put each parent with his children in a widget
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是原生的,也不是我所知道的任何插件。这当然是可以实现的,但需要大量的自定义编码。你想做的是一种边缘情况;您将顶级类别视为一种“标题”,并且 WordPress 假定每个类别都是一个类别。一般来说,我建议您最好使用自定义插件(理想情况下)或使用 ACF 或类似的插件构建的插件,为每种请求的数据类型引入自定义术语。但是,为了讨论,您必须执行以下操作:
admin_head
remove_meta_box
删除现有元框add_meta_boxes
add_meta_box
和您生成的详细信息来注册新的小部件save_post
(带有大量验证)来整理和保存这里有趣的挑战是,您被迫使用预先存在的数据结构 - WordPress 存储类别(和其他标签)以特定的方式,但您试图将其抽象为多个入口点。这意味着在渲染时,您必须从保存的数据结构中提取相关数据,而在保存时,您必须将所有这些入口点提交合并回预期的数据结构中。
Not natively, nor with any plugin I know of. It's certainly possible to accomplish but would require a fair bit of custom coding. What you're trying to do is sorta an edge-case; you're treating top-level categories as a sort of "header" and WordPress assumes each category is, well, a category. Generally, I'd suggest you'd be better off with a custom plugin (ideally) or something built with ACF or similar that introduces custom terms for each requested type of data. However, for the sake of discussion, you'd have to do something like this:
admin_head
remove_meta_box
to remove the existing meta boxadd_meta_boxes
add_meta_box
with your generated details to register a new widgetsave_post
(with a bunch of validation) to collate and saveThe fun challenge here is that you're forced to work with a pre-existing data structure - WordPress stores categories (and other tags) in a specific way, but you're trying to abstract that out to multiple entry points. This means that on render you have to extract the relevant data from the saved data structure, and on save you have to merge all those entry point submissions back into the expected data structure.