多亏toschos的提示,我才能解决这个问题。这是我使用的代码:
// Register the endpoint
function my_init() {
add_rewrite_endpoint(\'votes\', EP_ALL);
}
add_action(\'init\', \'my_init\');
// Execute a function when the endpoint is called
function my_redirect() {
global $wp_query;
if (isset($wp_query->query_vars[\'votes\'])) {
$wp_query->is_404 = false;
add_filter( \'wp_title\', \'my_title_votes\', 10, 2 );
// this will output the template-file "all-votes.php"
get_template_part( \'all-votes\' );
// Prevent WordPress from adding the front-page or 404 page to my output...
die();
}
}
add_action( \'template_redirect\', \'my_redirect\' );
function my_title_votes( $title, $sep ) {
return \'Votes-Title \' . $sep . \' \' . $title;
}
当我打开URL mysite时。com/vows/I获得自定义输出,即使没有包含该slug的页面:-)