本文整理自网络,侵删。
经过两天的正则表达式的学习,和研究wordpress的路由函数,成功实现了自定义wordpress路由功能,以下是路由规则的实现。
如果有自定义的url参数,要通过路由传递,必须通过wordpress的函数将参数添加进去:
代码如下:
//add query_args
function add_query_vars($aVars) {
$aVars[] = 'score';
$aVars[] = 'type'; // represents the name of the product category as shown in the URL
return $aVars;
}
add_filter('query_vars', 'add_query_vars');//wordpress过滤器
//add query_args
function add_query_vars($aVars) {
$aVars[] = 'score';
$aVars[] = 'type'; // represents the name of the product category as shown in the URL
return $aVars;
}
add_filter('query_vars', 'add_query_vars');//wordpress过滤器
同时在获取参数的页面也要用到wordpress的函数获取:
代码如下:
$type=isset($wp_query->query_vars['type'])?urldecode($wp_query->query_vars['type']):'';
$type=isset($wp_query->query_vars['type'])?urldecode($wp_query->query_vars['type']):'';
相关阅读 >>
百度官方推出的wordpress结构化数据插件百度sitemap
完美解决wordpress sae版改域名后不能进入后台的问题
wordpress中设置post type自定义文章类型的实例教程
wordpress忘记后台密码怎么办 轻松找回wp密码的方法
更多相关阅读请进入《wordpress》频道 >>
相关推荐
评论
管理员已关闭评论功能...
- 欢迎访问木庄网络博客
- 可复制:代码框内的文字。
- 方法:Ctrl+C。