Let's say I have a Wordpress blog: www.animals.com
I have a certain PHP file in my theme directory: www.animals.com/wp-content/themes/mytheme/db.php
Also, I have a custom template for that page, so I create a new page in the Wordpress administration panel to show db.php
: www.animals.com/database
So if I want to read something about lions, I just go to: www.animals.com/database/?animal=lion
(because that's the way I decided to write the PHP, inserting the value from $_GET['animal'] into the query, using PDO blah blah..)
Now, I would like to access www.animals.com/database/?animal=lion
as www.animals.com/lion
Should I use .htaccess or Wordpress Rewrite?
you need to call $wp_query->query_vars['dios']
so i added this to my theme's functions.php
function add_query_vars($new_var) {
$new_var[] = "dios";
return $new_var;
}
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($rules) {
$new_rules = array('([^/]+)' => 'index.php?pagename=dios&dios=$matches[1]');
$rules = $new_rules + $rules;
return $rules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
No comments:
Post a Comment