Page-Specific Rewrite Rules: Improvements?
-
Hello!
On one specific page (/projects/references/)in my blog I’d like to read values from the URL and work with them: cat_main, cat_sub and pid (project-id).
URL example: /projects/references/my_cat_main/my_cat_sub/my_projectidAfter a lot of search, trial & error I came to this solution:
// Adding Query Vars: function my_query_vars($vars){ $my_vars = array('cat_main','cat_sub','pid'); return array_merge($my_vars, $vars); } add_filter('query_vars', 'my_query_vars');
// Adding Rewrite Rules function my_rewrite_rules($rules){ $my_rule = array( 'projects/references/(.+)/(.+)/(.+)/?' => 'index.php?pagename=projects/references&cat_main=$matches[1]&cat_sub=$matches[2]&pid=$matches[3]', 'projects/references/(.+)/(.+)/?' => 'index.php?pagename=projects/references&cat_main=$matches[1]&cat_sub=$matches[2]', 'projects/references/(.+)/?' => 'index.php?pagename=projects/references&cat_main=$matches[1]' ); return array_merge($my_rule, $rules); } add_filter('page_rewrite_rules', 'my_rewrite_rules');
This work’s quite fine! *yeah*
But: I’m new to this, and so I’d like to ask YOU: Is this the way to do it? What could I improve?
For example I’m not so sure if it’s realy necessary to define 3 seperate rules?Another question: Is there a way to call different templates for the different rules? For example a list-template for both category-rules and a seperate template for the project-view?
Thanks a lot
Mark
- The topic ‘Page-Specific Rewrite Rules: Improvements?’ is closed to new replies.