加入收藏 | 设为首页 | 会员中心 | 我要投稿 许昌站长网 (https://www.0374zz.cn/)- 专属主机、负载均衡、智能边缘云、云防火墙、数据加密!
当前位置: 首页 > 教程 > 正文

DedeCMS系统TAG标签和分页伪静态设置教程

发布时间:2022-09-01 11:35:05 所属栏目:教程 来源:互联网
导读:现在好多CMS系统都有TAGS标签这项功能,知名的DEDECMS也有,但是它的标签功能很差,不利于seo优化,同时也有很多问题,比如:当前页不存在上一页时,链接为-1的问题,还有出现系统无此标签,可能已经移除的问题。 今天就教大家把标签伪静态(部分资料来源于
  现在好多CMS系统都有TAGS标签这项功能,知名的DEDECMS也有,但是它的标签功能很差,不利于seo优化,同时也有很多问题,比如:当前页不存在上一页时,链接为“-1”的问题,还有出现“系统无此标签,可能已经移除”的问题。
  今天就教大家把标签伪静态(部分资料来源于网络),同时也修复了一些上述提到的BUG。
  1.修改前台显示链接
  我们这里达到的效果就是使原来/tags.php?keywors更改为/tags/keywords.html。
  这里主要修改下调用的标签,在/include/taglib/tag.lib.php中,在87行找到
  $row['link'] = $cfg_cmsurl."/tags?".urlencode($row['keyword']);  
  将其改为:
  $row['link'] = $cfg_cmsurl."/tags/".urlencode($row['keyword']).".html";
  2.修改分页代码部分
  我们需要修改include/arc.taglist.class.php,找到分页函数,将其替换为:
 
  001
  Copy to ClipboardLiehuo.Net Codes引用的内容:[www.veryhuo.com]
  002
  /**
  003
  * 获取动态的分页列表
  004
  *
  005
  * @access public
  006
  * @param int $list_len 列表宽度
  007
  * @param string $listitem 列表样式
  008
  * @return string
  009
  */
  010
  function GetPageListDM($list_len,$listitem="info,index,end,pre,next,pageno")
  011
  {
  012
  $prepage="";
  013
  $nextpage="";
  014
  $prepagenum = $this->PageNo - 1;
  015
  $nextpagenum = $this->PageNo + 1;
  016
  if($list_len == "" || preg_match("/[^0-9]/", $list_len))
  017
  {
  018
  $list_len = 3;
  019
  }
  020
  $totalpage = $this->TotalPage;
  021
  if($totalpage <= 1 && $this->TotalResult > 0)
  022
  {
  023
  return "<span class="pageinfo">共1页/".$this->TotalResult."条</span>";
  024
  }
  025
  if($this->TotalResult == 0)
  026
  {
  027
  return "<span class="pageinfo">共0页/".$this->TotalResult."条</span>";
  028
  }
  029
  $maininfo = "<span class="pageinfo">共{$totalpage}页/".$this->TotalResult."条</span>rn";
  030
  $purl = $this->GetCurUrl();
  031
  $basename = basename($purl);
  032
  $tmpname = explode('.', $basename);
  033
   
  034
  $purl = str_replace($basename, '', $purl).urlencode($this->Tag);
  035
  //var_dump($purl);exit;
  036
  //$purl .= "?/".urlencode($this->Tag);
  037
   
  038
  //获得上一页和下一页的链接
  039
  //if($this->PageNo != 1) 这是修正上一页为负数的问题
  040
          if($this->PageNo != 1 && $this->PageNo != "")
  041
  {
  042
  $prepage.="<li><a href='".$purl."-$prepagenum'.html>上一页</a></li>rn";
  043
  $indexpage="<li><a href='".$purl."-1.html'>首页</a></li>rn";
  044
  }
  045
  else
  046
  {
  047
  $indexpage="<li><a>首页</a></li>rn";
  048
  }
  049
  if($this->PageNo!=$totalpage && $totalpage>1)
  050
  {
  051
  $nextpage.="<li><a href='".$purl."-$nextpagenum.html'>下一页</a></li>rn";
  052
  $endpage="<li><a href='".$purl."-$totalpage.html'>末页</a></li>rn";
  053
  }
  054
  else
  055
  {
  056
  $endpage="<li><a>末页</a></li>rn";
  057
  }
  058
   
  059
  //获得数字链接
  060
  $listdd="";
  061
  $total_list = $list_len * 2 + 1;
  062
  if($this->PageNo >= $total_list)
  063
  {
  064
  $j = $this->PageNo - $list_len;
  065
  $total_list = $this->PageNo + $list_len;
  066
  if($total_list > $totalpage)
  067
  {
  068
  $total_list = $totalpage;
  069
  }
  070
  }
  071
  else
  072
  {
  073
  $j=1;
  074
  if($total_list > $totalpage)
  075
  {
  076
  $total_list = $totalpage;
  077
  }
  078
  }
  079
  for($j; $j<=$total_list; $j++)
  080
  {
  081
  if($j == $this->PageNo)
  082
  {
  083
  $listdd.= "<li class="thisclass"><a>$j</a></li>rn";
  084
  }
  085
  else
  086
  {
  087
  $listdd.="<li><a href='".$purl."-$j.html'>".$j."</a></li>rn";
  088
  }
  089
  }
  090
  $plist = '';
  091
  if(preg_match('/info/i', $listitem))
  092
  {
  093
  $plist .= $maininfo.' ';
  094
  }
  095
  if(preg_match('/index/i', $listitem))
  096
  {
  097
  $plist .= $indexpage.' ';
  098
  }
  099
  if(preg_match('/pre/i', $listitem))
  100
  {
  101
  $plist .= $prepage.' ';
  102
  }
  103
  if(preg_match('/pageno/i', $listitem))
  104
  {
  105
  $plist .= $listdd.' ';
  106
  }
  107
  if(preg_match('/next/i', $listitem))
  108
  {
  109
  $plist .= $nextpage.' ';
  110
  }
  111
  if(preg_match('/end/i', $listitem))
  112
  {
  113
  $plist .= $endpage.' ';
  114
  }
  115
  return $plist;
  116
  }
  117
  3.设置伪静态规则
  118
   
  119
  我们这里以iis7为例子,设置以下规则:
  120
   
  121
  Copy to ClipboardLiehuo.Net Codes引用的内容:[www.veryhuo.com]
  122
  <?xml version="1.0" encoding="UTF-8"?>
  123
  <configuration>
  124
  <system.webServer>
  125
  <rewrite>
  126
  <rules>
  127
  <rule name="weather1" stopProcessing="true">
  128
  <match url="tags/([^-]+).html$" ignoreCase="true" />
  129
  <conditions logicalGrouping="MatchAll">
  130
  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  131
  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  132
  </conditions>
  133
  <action type="Rewrite" url="/tags.php?/{R:1}" appendQueryString="false" />
  134
  </rule>
  135
  <rule name="weather2" stopProcessing="true">
  136
  <match url="tags/([^-]+)-([0-9]+).html$" ignoreCase="true" />
  137
  <conditions logicalGrouping="MatchAll">
  138
  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  139
  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  140
  </conditions>
  141
  <action type="Rewrite" url="/tags.php?/{R:1}/{R:2}" appendQueryString="false" />
  142
  </rule>
  143
  </rules>
  144
  </rewrite>
  145
  </system.webServer>
  146
  </configuration>

(编辑:许昌站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读