I am building a site with several sections, and one of them is a special page to navigate through categories in a hierarchical style (you can navigate into categories/subcategories and see their children). So I have added a Page
and I have assigned a custom template to it in the Template
drop-down.
Maybe what I want to do is not possible, or it’s too tricky: I’d like to have my page, which URL is www.domain.com/tutorials
to display a top menu with the main categories. This menu is a WordPress menu registered with register_nav_menus
, with links to categories.
I’d like the items on the menu to point to that same page, with the slug of the category: www.domain.com/tutorials/my-category
(instead of www.domain.com/category/my-category
).
Each “category page” will show links to sub-categories that should have the same URL structure (i.e.: www.domain.com/tutorials/my-category/my-subcategory
) I know how to query for sub-categories and get the current category with get_query_var
, but again I have this problem producing the right URL for each one.
I’ve seen the pieces I need, like add_rewrite_rule()
, add_rewrite_tag()
or parse_request()
. I can also have wp_nav_menu_objects
and Walker_Nav_Menu
but I can’t put together a setup where my Tutorials
page doesn’t return a 404 if I add categories/subcategories to the URL (it only accepts going to www.domain.com/category/my-category
).
I have been able to render a menu pointing to my page by getting each menu $item->url and replacing ‘category’ by my page’s slug, so my only remaining issue is the 404 problem.
My WP settings are: Category base
is empty, and my permalink structure is /%category%/%postname%/
Could anyone point me in the right direction?