织梦cms系统TAG标签和分页伪静态设置教程

现在好多CMS系统都有TAGS标签这项功能,知名的DEDECMS也有,但是它的标签功能很差,不利于seo优化,同时也有很多问题,比如:当前页不存在上一页时,链接为“-1”的问题,还有出现“系统无此标签,可能已经移除”的问题。

 

今天小编就教大家把标签伪静态(部分资料来源于网络),同时也修复了一些上述提到的BUG。

 

1.修改前台显示链接 

 

我们这里达到的效果就是使原来/tags.php?keywors更改为/tags/keywords.html。 

 

这里主要修改下调用的标签,在/include/taglib/tag.lib.php中,在87行找到 

 

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

将其改为: 

 

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

 

2.修改分页代码部分

 

我们需要修改include/arc.taglist.class.php,找到分页函数,将其替换为:

 

001001 /**
002002 * 获取动态的分页列表
003003 *
004004 * @access public
005005 * @param int $list_len 列表宽度
006006 * @param string $listitem 列表样式
007007 * @return string
008008 */
009009 function GetPageListDM($list_len,$listitem="info,index,end,pre,next,pageno")
010010 {
011011 $prepage="";
012012 $nextpage="";
013013 $prepagenum = $this->PageNo - 1;
014014 $nextpagenum = $this->PageNo + 1;
015015 if($list_len == "" || preg_match("/[^0-9]/", $list_len))
016016 {
017017 $list_len = 3;
018018 }
019019 $totalpage = $this->TotalPage;
020020 if($totalpage <= 1 && $this->TotalResult > 0)
021021 {
022022 return "<span class=\"pageinfo\">共1页/".$this->TotalResult."条</span>";
023023 }
024024 if($this->TotalResult == 0)
025025 {
026026 return "<span class=\"pageinfo\">共0页/".$this->TotalResult."条</span>";
027027 }
028028 $maininfo = "<span class=\"pageinfo\">共{$totalpage}页/".$this->TotalResult."条</span>\r\n";
029029 $purl = $this->GetCurUrl();
030030 $basename basename($purl);
031031 $tmpname = explode('.', $basename);
032032
033033 $purl = str_replace($basename'', $purl).urlencode($this->Tag);
034034 //var_dump($purl);exit;
035035 //$purl .= "?/".urlencode($this->Tag);
036036
037037 //获得上一页和下一页的链接
038038 //if($this->PageNo != 1) 这是修正上一页为负数的问题
039039         if($this->PageNo != 1 && $this->PageNo != "")
040040 {
041041 $prepage.="<li><a href='".$purl."-$prepagenum'.html>上一页</a></li>\r\n";
042042 $indexpage="<li><a href='".$purl."-1.html'>首页</a></li>\r\n";
043043 }
044044 else
045045 {
046046 $indexpage="<li><a>首页</a></li>\r\n";
047047 }
048048 if($this->PageNo!=$totalpage && $totalpage>1)
049049 {
050050 $nextpage.="<li><a href='".$purl."-$nextpagenum.html'>下一页</a></li>\r\n";
051051 $endpage="<li><a href='".$purl."-$totalpage.html'>末页</a></li>\r\n";
052052 }
053053 else
054054 {
055055 $endpage="<li><a>末页</a></li>\r\n";
056056 }
057057
058058 //获得数字链接
059059 $listdd="";
060060 $total_list = $list_len * 2 + 1;
061061 if($this->PageNo >= $total_list)
062062 {
063063 $j = $this->PageNo - $list_len;
064064 $total_list = $this->PageNo + $list_len;
065065 if($total_list > $totalpage)
066066 {
067067 $total_list = $totalpage;
068068 }
069069 }
070070 else
071071 {
072072 $j=1;
073073 if($total_list > $totalpage)
074074 {
075075 $total_list = $totalpage;
076076 }
077077 }
078078 for($j; $j<=$total_list; $j++)
079079 {
080080 if($j == $this->PageNo)
081081 {
082082 $listdd.= "<li class=\"thisclass\"><a>$j</a></li>\r\n";
083083 }
084084 else
085085 {
086086 $listdd.="<li><a href='".$purl."-$j.html'>".$j."</a></li>\r\n";
087087 }
088088 }
089089 $plist = '';
090090 if(preg_match('/info/i', $listitem))
091091 {
092092 $plist .= $maininfo.' ';
093093 }
094094 if(preg_match('/index/i', $listitem))
095095 {
096096 $plist .= $indexpage.' ';
097097 }
098098 if(preg_match('/pre/i', $listitem))
099099 {
100100 $plist .= $prepage.' ';
101101 }
102102 if(preg_match('/pageno/i', $listitem))
103103 {
104104 $plist .= $listdd.' ';
105105 }
106106 if(preg_match('/next/i', $listitem))
107107 {
108108 $plist .= $nextpage.' ';
109109 }
110110 if(preg_match('/end/i', $listitem))
111111 {
112112 $plist .= $endpage.' ';
113113 }
114114 return $plist;
115115 }
116116 3.设置伪静态规则
117117
118118 我们这里以iis7为例子,设置以下规则:
119119
120120 Copy to ClipboardLiehuo.Net Codes引用的内容:[www.veryhuo]
121121 <?xml version="1.0" encoding="UTF-8"?>
122122 <configuration>
123123 <system.webServer>
124124 <rewrite>
125125 <rules>
126126 <rule name="weather1" stopProcessing="true">
127127 <match url="tags/([^-]+)\.html$" ignoreCase="true" />
128128 <conditions logicalGrouping="MatchAll">
129129 <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
130130 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
131131 </conditions>
132132 <action type="Rewrite" url="/tags.php?/{R:1}" appendQueryString="false" />
133133 </rule>
134134 <rule name="weather2" stopProcessing="true">
135135 <match url="tags/([^-]+)-([0-9]+)\.html$" ignoreCase="true" />
136136 <conditions logicalGrouping="MatchAll">
137137 <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
138138 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
139139 </conditions>
140140 <action type="Rewrite" url="/tags.php?/{R:1}/{R:2}" appendQueryString="false" />
141141 </rule>
142142 </rules>
143143 </rewrite>
144144 </system.webServer>
145145 </configuration>

好了,至此就搞定了。

https://www.qqzla/

更多推荐

织梦cms系统TAG标签和分页伪静态设置教程,小超辅助网