我正在尝试将一个ShowRevel标题和视频id放入一个URL中,然后页面可以访问该URL。
我有两个在同一个URL,它要么不工作,要么只有一个进来。当前找不到该页?(我一直在冲洗permalinks)
我想从中获取变量的Url看起来像目录/测试主管/显示卷轴/showreel-name/视频/111/
该网站目前位于一个名为independent\\u 02的测试文件夹中,但不确定这是否会影响任何内容?
这是代码;
function wpse13483_init() {
add_rewrite_rule( \'directors/(.+?)/showreels/([^/]+)?/?$\', \'index.php?category_name=$matches[1]&showreel=a\', \'top\' );
add_rewrite_rule( \'directors/(.+?)/showreels/([^/]+)/video/([^/]+)?/?$\', \'index.php?category_name=$matches[1]&showreel=c1&video=c2\', \'top\' );
// directors is a custom post_type and should go to single-directors.php
add_rewrite_rule( \'showreels/(.+?)/video/([^/]+)?/?$\', \'index.php?category_name=$matches[1]&video=b\', \'top\' );
// showreels is a custom post_type and should go to single-showreels.php
}
add_action( \'init\', \'wpse13483_init\' );
感谢您的帮助!
<小时>UPDATES - 这条规则现在主要起作用并捕获变量。然而,它将被归档。php而不是单一的控制器。php?
add_rewrite_rule( \'directors/(.+?)/showreels/([^/]*)/video/([^/]*)/?\', \'index.php?post_type=directors&showreel=$matches[2]&video=$matches[3]\', \'top\' );
// directors is a custom post_type and should go to single-directors.php
我想这和\'有关?post\\U type=控制器,但找不到任何关于加载单个的内容的引用。php
UPDATE 2查看Rewrite Analyzer,我认为它缺少post\\u类型的变量?
最合适的回答,由SO网友:v3nt 整理而成
这似乎奏效了!
?post_type=董事和;name=$匹配[1]似乎是关键
add_rewrite_rule( \'directors/([^/]*)/showreels/([^/]*)/video/([^/]*)/?\', \'index.php?post_type=directors&name=$matches[1]&showreel=$matches[2]&video=$matches[3]\', \'top\' );
现在是最终代码;
function wpse13483_init() {
add_rewrite_rule( \'directors/([^/]*)/showreels/([^/]*)/video/([^/]*)/?\', \'index.php?post_type=directors&name=$matches[1]&showreel=$matches[2]&video=$matches[3]\', \'top\' );
}
add_action( \'init\', \'wpse13483_init\' );
function wpa52794_query_vars( $vars) {
$vars[] = \'video\';
$vars[] = \'showreel\';
return $vars;
}
add_filter( \'query_vars\', \'wpa52794_query_vars\' );