中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

wordpress自定義url參數(shù)實現(xiàn)路由功能的代碼示例

經(jīng)過兩天的正則表達式的學習,和研究wordpress的路由函數(shù),成功實現(xiàn)了自定義wordpress路由功能,以下是路由規(guī)則的實現(xiàn)。
如果有自定義的url參數(shù),要通過路由傳遞,必須通過wordpress的函數(shù)將參數(shù)添加進去:

復制代碼 代碼如下:
//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過濾器

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

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

復制代碼 代碼如下:
//路由規(guī)則-根據(jù)時間排序以及各類別的最新條目
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');

復制代碼 代碼如下:
//路由規(guī)則-類別
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參數(shù)實現(xiàn)路由功能的代碼示例,轉載需保留來源!

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

主站蜘蛛池模板: 亚洲精品9999 | 久久亚| 国产精品美女久久久免费 | 日本不卡一区 | 久久青青| 精品影院 | 亚洲成av人影片在线观看 | 久草视频在线播放 | 日韩成人免费av | 午夜在线 | 日韩欧美字幕 | 亚洲视频一区在线观看 | 国产黄色在线 | 免费观看一级特黄欧美大片 | 99热精品在线 | 日韩成人一区 | 精品九九久久 | 91视频18| 香蕉久久a毛片 | 欧美一区二区三区的 | 懂色av一区二区三区在线播放 | 午夜在线| 性高朝久久久久久久3小时 av一区二区三区四区 | 91av视频| 精品综合 | 日韩视频在线一区 | 亚洲激情一区二区 | 日韩av一区在线观看 | 综合久久综合久久 | 久久午夜国产精品www忘忧草 | 欧美一区二区三区在线 | 亚洲精品国产第一综合99久久 | 午夜精品在线观看 | 色婷婷精品 | 国产99免费视频 | 91资源在线 | 91不卡在线 | 麻豆一区 | 天天曰天天干 | 精品在线一区 | 黄色在线免费观看视频网站 |