我有一个permalink,可以生成一些自定义内容,如:
http://mysite.com/extra-deal/91103/
这将带您进入由文件处理的页面:category-extra-deals.php
在该页面上,我获取URL的最后一部分(上例中为91103),并使用该部分对我需要的信息进行自定义数据库请求。我想退出使用id号(91103)并开始使用标题。
但将其更改为:
http://mysite.com/extra-deal/title-of-that-entry/
结果是404和模板category-extra-deals.php
从未接触过。我想模板会被点击,至少,即使找不到标题,但事实并非如此。
另一个示例。。。如果我访问:
http://mysite.com/extra-deal/9/
我会拿到category-extra-deals.php
模板,但没有内容,因为9不存在。但是,使用:
http://mysite.com/extra-deal/a/
我会得到404页。为什么当URL有一个数字时我会得到所需的模板,而当URL的同一部分有文本时我会得到404?
<小时>
Solution
我需要添加自己的重写规则以适应新的url结构。因此,以下url:
http://mysite.com/extra-deal/the-title-of-the-posting
将按以下规则处理:function add_rewrite_rules($aRules) {
$aNewRules = array(\'extra-deal/([^/]+)/?$\' => \'index.php?pagename=extra-deal&extradeal_title=$matches[1]\');
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter(\'rewrite_rules_array\', \'add_rewrite_rules\');
还有一件事,如果您注意到的话,url需要一个名为“extra deal\\u title”的参数。还需要添加,并通过以下方式完成:function add_query_vars($aVars) {
$aVars[] = "extradeal_title";
return $aVars;
}