Is it possible to create a menu with a category such that each time that I had a sub category that automatically display on the menu?
As far as I know, if I have a menu with the category “fruit”, and I create the subcategory “bananas”, I have to manually add it.
This depends on what kind of menu you are talking about:
1)
If you are talking about “custom menus” (found in the Backend under Design -> Menus) you can do the following:
Create a new function with the action hook
add_category
inside of this function, you can create a new post of type the menu
item type, which is added correctly to your menu
whenever a new category is published the menu item is added now
you should also hook into delete category, to keep your menu
up-to-date
2)
You could do much easier without a wordpress menu:
wp_list_categories
function)recursivley) reads your categories from the database
For option 1 to code you require some knowledge about WordPress though.
I prefer using
wp_list_categories
. Here is my code I used in my last project:You will get a list of all your categories and sub-categories.
After many research I found a trustful useful solution, this class works well:
Another alternative would be to use List Custom Taxonomy Widget, it might work in your use case (if you are not planning to use WP nav_menu).
To solve this problem i tried to create a plugin which automatically create menu item for publish category under it’s parent category if in menu.
Idea for plugin:
1.in code, i used “created_$taxonomy” action hook.
2.collect all the menu item ( by using wp_get_nav_menu_items)
3.and put condition if parent of publish category lies in menu-item than a menu-item created as sub menu of it’s parent category.(by using wp_update_nav_menu_item)
Note: plugin giving error (header already sent) and menu item not created when category publish.This may be another topic for problem but i put it here because this may be a solution if some suggest me where i am wrong.Sorry if i’m doing something wrong by putting it here
I coded my own for one my of clients
i am using to show all category and sub category of category as a menu in my project.
this is my approach, this works for product categories.