• 全国400电话网上服务平台
    强大号码库资源任选,方便,快捷,快速开通。
    咨询热线:400-1100-266  

    DedeCMS实现tag标签伪静态的方法
    POST TIME:2021-05-23 02:28

    目标:使DEDECMS原来的tags.php?/bnxbcom/  变动为/tags/bnxbcom.html 这种伪静态模式

    一、dede后台开启伪静态


    二、修改 /include/taglib/tag.lib.php

    大约87行找到


    $row['link'] = $cfg_cmsurl."/tags.php?/".urlencode($row['keyword'])."/";

    改成


    $row['link'] = $cfg_cmsurl."/tags/".urlencode($row['keyword']).".html";

     

    三、修改分页代码

    修改分页代码。同样打开include/arc.taglist.class.php,主要是//获得上一页和下一页的链接。将//获得上一页和下一页的链接  至  //获得数字链接之间的分页函数替换:

    也可以直接用下面代码替换同样部分代码

    (提示:网上有文章中讲的以下代码中的"pageinfo"是错误的,应该为\&;pageinfo\&;,不然会有错误提示哦!已经代码测试OK!)

     

    /** * 获取动态的分页列表
    *
    
    * @access public
    * @param int $list_len 列表宽度
    * @param string $listitem 列表样式
    * @return string
    */
    function GetPageListDM($list_len,$listitem="info,index,end,pre,next,pageno")
    {
    $prepage="";
    $nextpage="";
    $prepagenum = $this->PageNo - 1;
    $nextpagenum = $this->PageNo + 1;
    if($list_len == "" || preg_match("/[^0-9]/", $list_len))
    {
    $list_len = 3;
    }
    $totalpage = $this->TotalPage;
    if($totalpage <= 1 && $this->TotalResult > 0)
    {
    return "<span class=\&;pageinfo\&;>共1页/".$this->TotalResult."条</span>";
    }
    if($this->TotalResult == 0)
    {
    return "<span class=\&;pageinfo\&;>共0页/".$this->TotalResult."条</span>";
    }
    $maininfo = "<span class=\&;pageinfo\&;>共{$totalpage}页/".$this->TotalResult."条</span>rn";
    $purl = $this->GetCurUrl();
    $basename = basename($purl);
    $tmpname = explode('.', $basename);
    $purl = str_replace($basename, '', $purl).urlencode($this->Tag);
    //var_dump($purl);exit;
    //$purl .= "?/".urlencode($this->Tag);
    //获得上一页和下一页的链接
    if($this->PageNo != 1)
    {
    $prepage.="<li><a href='".$purl."-$prepagenum'.html>上一页</a></li>rn";
    $indexpage="<li><a href='".$purl."-1.html'>首页</a></li>rn";
    }
    else
    {
    $indexpage="<li><a>首页</a></li>rn";
    }
    if($this->PageNo!=$totalpage && $totalpage>1)
    {
    $nextpage.="<li><a href='".$purl."-$nextpagenum.html'>下一页</a></li>rn";
    $endpage="<li><a href='".$purl."-$totalpage.html'>末页</a></li>rn";
    }
    else
    {
    $endpage="<li><a>末页</a></li>rn";
    }
    //获得数字链接
    $listdd="";
    $total_list = $list_len * 2 + 1;
    if($this->PageNo >= $total_list)
    {
    $j = $this->PageNo - $list_len;
    $total_list = $this->PageNo + $list_len;
    if($total_list > $totalpage)
    {
    $total_list = $totalpage;
    }
    }
    else
    {
    $j=1;
    if($total_list > $totalpage)
    {
    $total_list = $totalpage;
    }
    }
    for($j; $j<=$total_list; $j++)
    {
    if($j == $this->PageNo)
    {
    $listdd.= "<li class=\&;thisclass\&;><a>$j</a></li>rn";
    }
    else
    {
    $listdd.="<li><a href='".$purl."-$j.html'>".$j."</a></li>rn";
    }
    }
    $plist = '';
    if(preg_match('/info/i', $listitem))
    {
    $plist .= $maininfo.' ';
    }
    if(preg_match('/index/i', $listitem))
    {
    $plist .= $indexpage.' ';
    }
    if(preg_match('/pre/i', $listitem))
    {
    $plist .= $prepage.' ';
    }
    if(preg_match('/pageno/i', $listitem))
    {
    $plist .= $listdd.' ';
    }
    if(preg_match('/next/i', $listitem))
    {
    $plist .= $nextpage.' ';
    }
    if(preg_match('/end/i', $listitem))
    {
    $plist .= $endpage.' ';
    }
    return $plist;
    }

     

    四、打开templets/default/taglist.htm

    找到   

    <strong>当前位置:</strong>:<a href="{dede:global.cfg_cmsurl/}/">主页</a> &gt; <a href='tags.php'>TAG标签</a> &gt; {dede:field.title /}

    修改为    

    <strong>当前位置:</strong>:<a href="{dede:global.cfg_cmsurl/}/">主页</a> &gt; <a href='/tags.html'>TAG标签</a> &gt; {dede:field.title /}

    五、httpd.ini 文件里加


     

    RewriteRule ^(.*)/tags\.html $1/tags\.php
    
    
    RewriteRule ^(.*)/tags/(.*).html $1/tags\.php\?$2
    
    
    
    如果是HTACCESS,那使用下面规则
    
    RewriteEngine on
    RewriteBase /
    RewriteRule ^tags/([0-9]+)_([0-9]+).html$        tags.php?tagid=$1&PageNo=$2 [L]
    RewriteRule ^tags/([0-9]+).html$                tags.php?tagid=$1 [L]

    
    关于我们 | 付款方式 | 建站知识 | 增值服务 | 网站模板
    Copyright © 2003-2016
    时间:9:00-21:00 (节假日不休)
    版权所有:巨人网络(扬州)科技有限公司
    总部地址:江苏省信息产业基地11号楼四层
    《增值电信业务经营许可证》 苏B2-20120278
    X

    截屏,微信识别二维码

    微信号:veteran88

    (点击微信号复制,添加好友)

     打开微信

    微信号已复制,请打开微信添加咨询详情!