最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

taxonomy - Limit categories to hierarchal depth of 2

programmeradmin1浏览0评论

Is there a way to limit the standard post categories to only allow one level of subcategories?

For example, allow the following:

Fruit 
> Apple

Veg
> Lettuce  

But from here, do not allow "Apple" or "Lettuce" to be a parent.

Is this possible and how can I do it?

Edit: The categories will be the primary method of navigation and I want to stop clients from adding endless levels of sub-categories and overcomplicating the navigation. I know I could just tell them, but I think we all know what clients are like. 1 level of sub-category is useful in this case, 10 is a mess.

Is there a way to limit the standard post categories to only allow one level of subcategories?

For example, allow the following:

Fruit 
> Apple

Veg
> Lettuce  

But from here, do not allow "Apple" or "Lettuce" to be a parent.

Is this possible and how can I do it?

Edit: The categories will be the primary method of navigation and I want to stop clients from adding endless levels of sub-categories and overcomplicating the navigation. I know I could just tell them, but I think we all know what clients are like. 1 level of sub-category is useful in this case, 10 is a mess.

Share Improve this question edited Nov 13, 2020 at 16:39 Mr DC asked Nov 13, 2020 at 16:12 Mr DCMr DC 133 bronze badges 5
  • Why? What is your aim - perhaps explain how you tried to achieve this also, ir order to get some relevant responses. – Q Studio Commented Nov 13, 2020 at 16:14
  • I have edited the question to clarify my reasons. – Mr DC Commented Nov 13, 2020 at 16:39
  • Noting that nothing prevents this in the database, so multiple UI based solutions will be needed, e.g. preventing it in the block editor UI, preventing it in the term management page when added, preventing it in the term edit screen, etc. Doing it via hooks might work but would lead to broken UIs. Suffice to say it is going to be a significant amount of work to do this, and require someone with advanced PHP CSS and React skills to accomplish thoroughly – Tom J Nowell Commented Nov 13, 2020 at 17:23
  • Of course you could prevent your navigation from displaying a 3rd level and tell your client it isn't currently supported, and that making 3rd level items visible would require billable design work – Tom J Nowell Commented Nov 13, 2020 at 17:26
  • Thanks @TomJNowell - this is pretty much what I'm looking for. I was hoping there was a way to restrict it without extensive modification - Clearly there is not. – Mr DC Commented Nov 16, 2020 at 9:57
Add a comment  | 

1 Answer 1

Reset to default 0

I would suggest you hand-build the navigation menu using the selected taxonomy terms, not using a script to automatically add them, which is where you would have problems with new terms being added.

发布评论

评论列表(0)

  1. 暂无评论