我正在尝试重写自定义页面模板的网址 链接http://pm.com/cusotm-page/7170-West-9th-Avenue-Lakewood-CO-80214/29415331/RES/METRO应写为
functions.php中的代码是
add_action( 'init', 'wpa5413_init' );
function wpa5413_init(){
add_rewrite_tag('%title%','([^&]+)');
add_rewrite_tag('%ppid%','([^&]+)');
add_rewrite_tag('%property%','([^&]+)');
add_rewrite_tag('%originator%','([^&]+)');
add_rewrite_rule('^cusotm-page-homendo/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$','cusotm-page/?title=$matches[1]&ppid=$matches[2]&property=$matches[3]&originator=$matches[4]','top');
}
你能告诉我我做错了什么吗?是正则表达式正确
PS“我刷新了重写规则,get变量添加了add_query_arg
答案 0 :(得分:0)
好的,解决方案是在重写时使用带有pagename的index.php
function wpa5413_init(){
add_rewrite_tag('%title%','([^&]+)');
add_rewrite_tag('%ppid%','([^&]+)');
add_rewrite_tag('%property%','([^&]+)');
add_rewrite_tag('%originator%','([^&]+)');
add_rewrite_rule('^cusotm-page/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$','index.php?pagename=cusotm-page&title=$matches[1]&ppid=$matches[2]&property=$matches[3]&originator=$matches[4]','top');
}
这将重写网址,http://pm.com/cusotm-page/7170-West-9th-Avenue-Lakewood-CO-80214/29415331/RES/METRO之类的链接将变为可用。 但是$ _GET ['title']不起作用 - 但您可以使用$ wp_query-> query_vars ['title']
访问变量还要确保在显示nice链接之前使用add_query_arg。
希望它有助于某人...