您的代码应该可以工作。线路:
include (get_template_directory_uri() . \'/articles.php\');
需要在服务器配置中设置allow\\u url\\u include=1,因为您正试图通过http包含文件。你能检查一下这个吗?
您还必须知道,template\\u redirect应该用于真正的重定向include()
这里可能有不希望的影响。我认为您真正想要的是template\\u包括:
add_filter(\'template_include\', \'my_template_include\');
function my_template_include( $template ) {
global $wp->query;
if ( array_key_exists( \'articles\', $wp_query->query_vars ) ) {
return get_template_directory() . \'/articles.php\';
}
return $template;
}
下面是我的代码:
function foo_change_author_base() {
global $wp_rewrite;
$wp_rewrite->author_base = \'writer\';
}
add_filter( \'init\', \'foo_change_author_base\', 0 );
function foo_rewrite_rule()
{
add_rewrite_rule( \'writer/([^/]+)/articles/page/([0-9]{1,})/?$\', \'index.php?author_name=$matches[1]&articles=1&paged=$matches[2]\', \'top\' );
//If you don\'t want the last trailing slash change the las /?$ to just $
add_rewrite_rule( \'writer/([^/]+)/articles/?$\', \'index.php?author_name=$matches[1]&articles=1\', \'top\' );
}
add_action( \'init\', \'foo_rewrite_rule\' );
function foo_add_vars($vars) {
$vars[] = \'articles\';
return $vars;
}
add_filter(\'query_vars\', \'foo_add_vars\');
function foo_add_endpoint() {
add_rewrite_endpoint( \'articles\', EP_AUTHORS );
}
//add_action( \'init\', \'foo_add_endpoint\'); // Commented out
// Edit: add_rewrite_endpoint is not needed when using add_rewrite_rule
// auto-add the articles endpoint to author links
function foo_author_link_filter( $link, $author_id, $author_nicename ) {
return user_trailingslashit($link) . \'articles/\';
}
add_filter( \'author_link\', \'foo_author_link_filter\', 20, 3);
add_filter(\'template_include\', \'foo_template_include\');
function foo_template_include( $template ) {
global $wp_query;
//You may need some other checks
if ( array_key_exists( \'articles\', $wp_query->query_vars ) ) {
return get_template_directory() . \'/articles.php\';
}
return $template;
}
现在转到您的站点。com/作者/作者\\u姓名/文章/