phpcms v9实现首页像WordPress一样的动态分页

2014-05-10 14:35:25   来源:OKXUN.com

本文讲解phpcms v9如何在首页实现像WordPress博客系统一样的分页,如:www.okxun.com/page/2,方法如下:

1、在apache中设置伪静态如下:

RewriteEngine on    RewriteRule /page/([0-9]+) /index.php?m=content&c=index&a=init&page=$1   Options FollowSymLinks      AllowOverride All      Order allow,deny      Allow from all        DocumentRoot "c:/www/php"   DirectoryIndex page/1   ServerName www.okxun.com

2、在phpcms\modules\content\index.php文件中,找到init()方法:$SEO = seo($siteid);在这一句上面加入$page = intval($_GET['page']);

3、修改phpcms\libs\functions\global.func.php中pageurl($urlrule, $page, $array = array())函数:

原代码如下:

function pageurl($urlrule, $page, $array = array()) {
    if(strpos($urlrule, '~')) {
        $urlrules = explode('~', $urlrule);
        $urlrule = $page < 2 ? $urlrules[0] : $urlrules[1];
    }
    $findme = array('{$page}');
    $replaceme = array($page);
    if (is_array($array)) foreach ($array as $k=>$v) {
        $findme[] = '{$'.$k.'}';
        $replaceme[] = $v;
    }
    $url = str_replace($findme, $replaceme, $urlrule);
    $url = str_replace(array('http://','//','~'), array('~','/','http://'), $url);
    return $url;
}

修改为:

function pageurl($urlrule, $page, $array = array()) {
    if($page == 0){$page= 1;}
    if(strpos($urlrule, '~')) {
        $urlrules = explode('~', $urlrule);
        $urlrule = $page < 2 ? $urlrules[0] : $urlrules[1];
    }    
    /*$find = "index.php?m=content&c=create_html&a=public_index&pc_hash=";
    $rel_url =  strstr($urlrule,$find);
    if(!empty($rel_url)){
        $urlrule = 'page/{$page}';
    }*/
     
    $finds = "/page\/[1-9]+/";   
    preg_match($finds,$urlrule,$matches);
    if(!empty($matches)){
        $newurl = explode("?", $urlrule);    
        $urlrule = substr_replace($newurl[0],'{$page}',26);      
    }    
    $finds1 = "/\?page=\{[$]{1}page\}/";
    preg_match($finds1,$urlrule,$matches01);
    if(!empty($matches01)){
    $newurls = str_replace("?", "", $matches01[0]);
    $urlrule =str_replace("=", "/", $newurls);
    }
        
    $findme = array('{$page}');
    $replaceme = array($page);   
    if (is_array($array)) foreach ($array as $k=>$v) {
        $findme[] = '{$'.$k.'}';
        $replaceme[] = $v;
    }
    $url = str_replace($findme, $replaceme, $urlrule);
    $url = str_replace(array('http://','//','~'), array('~','/','http://'), $url);
    return $url;
}