可以通过创建一个“假页面”来做到这一点,而不是在下面的仪表板区域中创建页面Pages -> Add New
然后从中选择模板Page Attributes 或者通过创建与slug或id匹配的模板,例如page-{slug}.php
或page-{id}.php
相反,您可以使用重写规则与挂接操作的组合template_redirect
以达到预期的结果。
你可以在我的answer 到this question.
我将在下面复制我的片段,但完整的解释应该在上面的回答中阅读。
步骤1:
add_action(\'init\', \'fake_page_rewrite\');
function fake_page_rewrite(){
global $wp_rewrite;
//set up our query variable %fake_page% which equates to index.php?fake_page=
add_rewrite_tag( \'%fake_page%\', \'([^&]+)\');
//add rewrite rule that matches /blog/page/2, /blog/page/3, /blog/page/4, etc..
add_rewrite_rule(\'^blog/page/?([0-9])?\',\'index.php?fake_page=blog&paged=$matches[1]\',\'top\');
//add rewrite rule that matches /blog
add_rewrite_rule(\'^blog/?\',\'index.php?fake_page=blog\',\'top\');
//add endpoint, in this case \'blog\' to satisfy our rewrite rule /blog, /blog/page/ etc..
add_rewrite_endpoint( \'blog\', EP_PERMALINK | EP_PAGES );
//flush rules to get this to work properly
$wp_rewrite->flush_rules();
}
第2步:
add_action(\'template_redirect\', \'fake_page_redirect\');
function fake_page_redirect(){
global $wp;
//retrieve the query vars and store as variable $template
$template = $wp->query_vars;
//pass the $template variable into the conditional statement and
//check if the key \'fake_page\' is one of the query_vars held in the $template array
//and that \'blog\' is equal to the value of the key which is set
if ( array_key_exists( \'fake_page\', $template ) && \'blog\' == $template[\'fake_page\'] ) {
//if the key \'fake_page\' exists and \'blog\' matches the value of that key
//then return the template specified below to handle presentation
include( get_template_directory().\'/your-template-name-here.php\' );
exit;
}
}
注意:可能需要一些调整来关联各个推特ID,但我们需要查看与推特相关的代码。
这些片段进入您的functions.php
文件当然,您应该更改任何参数,否则应该满足您的期望end point. 那么你看到了什么blog
成为whatever-you-want
等等。第二个代码段中的模板名称应与所需的模板相对应。