When a user browses to a URI beginning with “/forums”, WordPress should call a specified template. For example, all of these URLs:
- mysite.com/forums
- mysite.com/forums/questions
- mysite.com/forums/questions/1/my-question
- mysite.com/forums/questions/ask
- mysite.com/forums/users
… should call the following template: mytheme/page-forums.php
I believe this involves WP_Rewrite, but I have no clue what to do from here.
Any ideas?
I’ve included some code that I use whenever I need to make additions to the WordPress rewrite rules. It injects additional rules into the normal WordPress rewrite logic so you can direct WordPress to specific template files based on the URL. You can modify it to your needs, by adding more rules to the create_rewrite_rules() function, and additional query_vars to the add_query_vars() function.