所以我有一个网站,大约有6种自定义帖子类型。其中三种帖子类型附加到一个自定义分类法。
我希望能够在侧边栏中列出\\u猫,并弹出一个url,如../%post_type%/%taxonomy%/ 让这个带你去taxonomy-%taxonomy%.php 模板并仅返回%post_type%.
我可以创建一个条件来读取当前%post_type% 并在taxonomy-%taxonomy%.php 文件我需要一些关于修改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:
实践领域是一种分类法。尝试添加一个变量,我可以使用该变量在分类法实践区域中按帖子类型过滤分类法。phpfunction 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\')