我在用这个example 重写url以加载给定文件car-details.php
但我还是出错了Page not found 当我访问domain.com/account/account_page/9 我怎样才能让它工作。
class Your_Class
{
public function init()
{
add_filter( \'template_include\', array( $this, \'include_template\' ) );
add_filter( \'init\', array( $this, \'rewrite_rules\' ) );
}
public function include_template( $template )
{
//try and get the query var we registered in our query_vars() function
$account_page = get_query_var( \'account_page\' );
//if the query var has data, we must be on the right page, load our custom template
if ( $account_page ) {
return CUSTOMER_CAR_PLUGIN_DIR.\'pages/customer-car-details.php\';
}
return $template;
}
public function flush_rules()
{
$this->rewrite_rules();
flush_rewrite_rules();
}
public function rewrite_rules()
{
add_rewrite_rule( \'account/(.+?)/?$\', \'index.php?account_page=$matches[1]\', \'top\');
add_rewrite_tag( \'%account_page%\', \'([^&]+)\' );
}
}
add_action( \'plugins_loaded\', array( new Your_Class, \'init\' ) );
// One time activation functions
register_activation_hook( CUSTOMER_CAR_PLUGIN_DIR, array( new Your_Class, \'flush_rules\' ) );
}