Quick\'n\'dirty类执行以下操作(您需要手动刷新永久链接的管理设置):
<?php
/**
* Add query args & vars & redirect stuff somewhere else
* Could be extended to support arrays of query args on input
* @package Rewrite Class
* @author F.J.Kaiser
*/
class wpseAddRewriteRules
{
var $file_name;
var $query_arg;
var $query_var;
function __construct( file_name, query_arg, query_var )
{
$this->file_name = $file_name;
$this->query_arg = $query_arg;
$this->query_var = $query_var;
add_action( \'wp_loaded\', array( &$this, \'add_rewrite_rule\') );
add_filter( \'query_vars\', array( &$this, \'add_query_vars\') );
add_action( \'parse_request\', array( &$this, \'parse_request\') );
}
function add_rewrite_rule()
{
add_rewrite_rule(
"{$this->file_name}.php$"
,"index.php?{$this->query_arg}={$this->query_var}"
,\'top\'
);
}
function add_query_vars( $query_vars )
{
$query_vars[] = $this->query_arg;
return $query_vars;
}
function parse_request( &$wp )
{
if ( array_key_exists( $this->query_arg, $wp->query_vars ) ) {
include plugin_dir_path( __FILE__ )."{$this->file_name}.php";
exit();
}
return;
}
}
注意:我只是把大脑的背面写了下来,所以对任何事情都不提防。输入错误(&A);这些可能隐藏在那里