所以我有一个大约有6种自定义帖子类型的网站 . 这些帖子类型中的三种都附加到一个自定义分类中 .
我希望能够在侧边栏中列出list_cats并吐出像 ../%post_type%/%taxonomy%/ 这样的网址,并将其带到 taxonomy-%taxonomy%.php 模板并仅返回 %post_type% 的结果 .
我可以创建一个条件,它将在 taxonomy-%taxonomy%.php 文件中正确读取当前 %post_type% 和样式 . 我需要一些最有效的方法来修改URL以将 %post_type% 传递给查询 .
提前致谢 . 我搜索了几天没有明确的答案 .
So here are my feeble attempts at a solution yet they are one big FAIL 这是基于rlmseo.com在这里找到答案的讨论 .
Trying to add the post type to a variable to use in the Query:
练习区是一种分类法 . 尝试在taxonomy-practice-areas.php中添加一个可用于过滤分类的变量
function add_query_vars($aVars) {
$aVars[] = "cust_pt_var"; // represents the name of the custom post type as shown in the URL
return $aVars;
}
// hook add_query_vars function into query_vars
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($aRules) {
$aNewRules = array('practice-areas/([^/]+)/pt/([^/]+)/?$' => 'index.php?practice-areas=$matches[1]&cust_pt_var=$matches[2]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
// hook add_rewrite_rules function into rewrite_rules_array
add_filter('rewrite_rules_array', 'add_rewrite_rules')
Trying to pass query variables in the rewrite
尝试在重写时将查询类型(组合和客户)以及练习区分类术语添加到查询中 .
function add_rewrite_rules($aRules) {
$aNewRules = array('portfolio/practice-areas/([^/]+)/?$' => 'index.php?post_type=portfolio&practice-areas=$matches[1]');
$aNewRules = array('clients/practice-areas/([^/]+)/?$' => 'index.php?post_type=clients&practice-areas=$matches[1]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
// hook add_rewrite_rules function into rewrite_rules_array
add_filter('rewrite_rules_array', 'add_rewrite_rules')
2 回答
您应该能够通过修改WP的重写规则来实现这一目标:
这是不完整的,您需要更改目标URL和规则本身,但这是基础 . 实施后重新保存固定链接设置一次 .
page
是当用户访问此URL时指向的页面的slug(在本例中为domain.com/page/remove/432
),$matches[1]
应该是URL中remove/
之后的数字 . 此编号可通过稍后指定的变量访问,目标页面模板上的$query_vars[] = 'removeid';
/ '$removeid'将是URL中的编号(如果已指定) .好的,所以我把重写完全放在一起,然后使用$ _POST解决方案 . 它工作得很好,我的URL没有任何污点 .
Put in Destination Page:
Put in Originating Page: