本文整理自网络,侵删。
经过两天的正则表达式的学习,和研究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 thickbox 点击图片显示下一张图的修改方法
wordpress中给媒体文件添加分类和标签的php功能实现
wordpress加入短代码运行框(运行代码复制代码清空代码无插件)
wordpress通过当前文章的id获取文章标题内容简介的信息
详解wordpress开发中get_header()获取头部函数的用法
更多相关阅读请进入《wordpress》频道 >>