天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

wordpress自定義url參數實現路由功能的代碼示例

經過兩天的正則表達式的學習,和研究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過濾器

同時在獲取參數的頁面也要用到wordpress的函數獲取:

復制代碼 代碼如下:
$type=isset($wp_query->query_vars['type'])?urldecode($wp_query->query_vars['type']):'';

復制代碼 代碼如下:
//路由規則-根據時間排序以及各類別的最新條目
function add_rewrite_rules($aRules) {
    $aNewRules = array(
        'text/([^latest][^/]+)/?(/page/([0-9]+)?)?/?$' => 'index.php?cat=2&score=$matches[1]&paged=$matches[3]',
        'image/([^latest][^/]+)/?(/page/([0-9]+)?)?/?$'=>'index.php?cat=3&score=$matches[1]&paged=$matches[3]',
        'video/([^latest][^/]+)/?(/page/([0-9]+)?)?/?$'=>'index.php?cat=4&score=$matches[1]&paged=$matches[3]',
        'resource/([^latest][^/]+)/?(/page/([0-9]+)?)?/?$'=>'index.php?cat=5&score=$matches[1]&paged=$matches[3]',
        'text/(latest)/?(/page/([0-9]+)?)?/?$'=>'index.php?cat=2&type=$matches[1]&paged=$matches[3]',
        'image/(latest)/?(/page/([0-9]+)?)?/?$'=>'index.php?cat=3&type=$matches[1]&paged=$matches[3]',
        'video/(latest)/?(/page/([0-9]+)?)?/?$'=>'index.php?cat=4&type=$matches[1]&paged=$matches[3]',
        'resource/(latest)/?$'=>'index.php?cat=5&type=$matches[1]',
        '(month)/?(/page/([0-9]+)?)?/?$'=>'index.php?score=$matches[1]&paged=$matches[3]',
        '(24hr)/?(/page/([0-9]+)?)?/?$'=>'index.php?score=$matches[1]&paged=$matches[3]',
    );
    $aRules = $aNewRules + $aRules;
    return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');

復制代碼 代碼如下:
//路由規則-類別
add_rewrite_rule('^text/?(/page/([0-9]+)?)?/?$','index.php?cat=2&paged=$matches[2]','top'); //對應的類別ID
add_rewrite_rule('^image/?(/page/([0-9]+)?)?/?$','index.php?cat=3&paged=$matches[2]','top');
add_rewrite_rule('^video/?(/page/([0-9]+)?)?/?$','index.php?cat=4&paged=$matches[2]','top');
add_rewrite_rule('^resource/?(/page/([0-9]+)?)?/?$','index.php?cat=5&paged=$matches[2]','top');

php技術wordpress自定義url參數實現路由功能的代碼示例,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 韩国和日本免费不卡在线 | 欧美精品久久久久久久久大尺度 | 中国农村真实bbwbbwbbw | 99久在线国内在线播放免费观看 | 日本特交大片免费观看 | 国色精品VA在线观看免费视频 | 亚洲国产精品天堂在线播放 | AV色蜜桃一区二区三区 | 影音先锋亚洲AV少妇熟女 | 精品无码国产自产在线观看水浒传 | 俄罗斯大白屁股 | 国产成人国产在线观看入口 | 精品手机在线1卡二卡3卡四卡 | 亚洲色偷偷偷网站色偷一区人人藻 | 蜜臀久久99精品久久久久久做爰 | 69人体阴展网 | 日本人作爰啪啪全过程 | 精品久久久噜噜噜久久7 | 忘忧草在线影院WWW日本动漫 | 欧美性黑吊xxx| 玩50岁四川熟女大白屁股直播 | 久久福利影院 | 成人精品亚洲 | 国产精品国产三级国产专区53 | 攻把受做哭边走边肉楼梯PLAY | sm主人调教揉花蒂H SM双性精跪趴灌憋尿调教H | 13小箩利洗澡无码视频APP | 韩国无遮羞禁动漫在线观看96 | 日韩AV无码一区二区三区不卡毛片 | 日本久久和电影 | 91亚洲 欧美 国产 制服 动漫 | 红番阁免费观看 | 91区国产福利在线观看午夜 | 漂亮的保姆5电影免费观看完整版中文 | 少妇的肉体AA片免费观看 | 国产激情一级毛片久久久 | 666永久视频在线 | 伊人狼人久久精品热9 | 久久国产露脸老熟女熟69 | 亚洲国产精品高清在线 | 亚洲AV无码国产精品色午夜情 |