Custom Category/Subcategory structure

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 dropdown.

Maybe what I want to do is not possible, or it’s too tricky: I’d like to have my page, which URL is 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 in the menu to point to that same page, with the slug of the category: (instead of

Each “category page” will have links to sub-categories that should have the same URL structure (i.e.: 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 to 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

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?

Read more here:: Custom Category/Subcategory structure

Leave a Reply

Your email address will not be published. Required fields are marked *