测试的版本是 dedecms5.7sp2 gbk
一、说明:本修改适用5.7sp2 gbk,可以生成网站所有TAG列表的静态网页文件,还有生成tag的首页静态文件。
修改前,请备份相关的原始文件。
二、修改步骤:
1、在DEDE网站根目录,建立“tag”目录(小写)
2、在DEDE后台SQL运行器里,执行以下一条SQL:
ALTER TABLE `#@__tagindex` ADD `maketime` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';
3、增加文件:
把文件上传到对应的目录 切记备份文件
只上传压缩包里面的 这3个文件夹 其他文件不用上传
4、修改文件:
1)打开 服务器上的 dede/inc/inc_menu.php
第142行 插入
<m:item name='更新TAG静态' link='makehtml_tag.php' rank='sys_MakeHtml' target='main' />
2)打开 服务器上的 include/taglib/tag.lib.php 第87行 替换成
$row['link'] = nic_tag_url($row['id']); //新加代码,TAG静态化
如果不会 那么打包的文件里面有 tag.lib.php 覆盖到对应的位置即可 include/taglib/tag.lib.php
3)打开 服务器上的 include/extend.func.php 把里面的代码 换成如下
<?php
function litimgurls($imgid=0) { global $lit_imglist,$dsql; //获取附加表 $row = $dsql->GetOne("SELECT c.addtable FROM #@__archives AS a LEFT JOIN #@__channeltype AS c ON a.channel=c.id where a.id='$imgid'"); $addtable = trim($row['addtable']); //获取图片附加表imgurls字段内容进行处理 $row = $dsql->GetOne("Select imgurls From `$addtable` where aid='$imgid'"); //调用inc_channel_unit.php中ChannelUnit类 $ChannelUnit = new ChannelUnit(2,$imgid); //调用ChannelUnit类中GetlitImgLinks方法处理缩略图 $lit_imglist = $ChannelUnit->GetlitImgLinks($row['imgurls']); //返回结果 return $lit_imglist; } //获取TAG静态地址, function nic_tag_url($tid) { global $dsql; $sql = "select * from #@__tagindex where id='$tid' "; if ($arcRow = $dsql->GetOne($sql)){ //$str = $GLOBALS['cfg_cmspath']."/tag/".ceil($tid/100)."/".Getpinyin($arcRow["tag"])."_".$tid."_1.html"; //目录结构为:每100个ID为一个目录,从 /tag/1/ 开始 $pinyin_title = getfirstchar($arcRow["tag"]); $pinyin_title = str_replace("?","",$pinyin_title); $pinyin_title = str_replace(":","",$pinyin_title); $str = $GLOBALS['cfg_cmspath']."/tag/".$pinyin_title."_".$tid."_1.html"; //目录结构为:/tag/拼音_ID_1.html 开始 }else $str="ID为$tid的TAG已被删除!"; return $str; } //获取指定文章的TAG到相关TAG列表页的地址, by NIC QQ:2384419 function nic_arc_tag_link($aid) { global $dsql; $sql = "select tid from #@__taglist where aid='$aid' group by tid "; $dsql->Execute('ala',$sql); while($row=$dsql->GetObject('ala')){ $url=nic_tag_url($row->tid); if ($arcRow = $dsql->GetOne("select * from #@__tagindex where id='".$row->tid."' ")) $tag=$arcRow["tag"]; else $tag=""; $str.=" <a href='".$url."' target=_blank><b>".$tag."</b></a> "; } return $str; } function getfirstchar($s0) { $fchar = ord(substr($s0, 0, 1)); if (($fchar >= ord("a") and $fchar <= ord("z"))or($fchar >= ord("A") and $fchar <= ord("Z"))) return strtoupper(chr($fchar)); $s = $s0; $asc = ord($s{0}) * 256 + ord($s{1})-65536; if ($asc >= -20319 and $asc <= -20284)return "A"; if ($asc >= -20283 and $asc <= -19776)return "B"; if ($asc >= -19775 and $asc <= -19219)return "C"; if ($asc >= -19218 and $asc <= -18711)return "D"; if ($asc >= -18710 and $asc <= -18527)return "E"; if ($asc >= -18526 and $asc <= -18240)return "F"; if ($asc >= -18239 and $asc <= -17923)return "G"; if ($asc >= -17922 and $asc <= -17418)return "H"; if ($asc >= -17417 and $asc <= -16475)return "J"; if ($asc >= -16474 and $asc <= -16213)return "K"; if ($asc >= -16212 and $asc <= -15641)return "L"; if ($asc >= -15640 and $asc <= -15166)return "M"; if ($asc >= -15165 and $asc <= -14923)return "N"; if ($asc >= -14922 and $asc <= -14915)return "O"; if ($asc >= -14914 and $asc <= -14631)return "P"; if ($asc >= -14630 and $asc <= -14150)return "Q"; if ($asc >= -14149 and $asc <= -14091)return "R"; if ($asc >= -14090 and $asc <= -13319)return "S"; if ($asc >= -13318 and $asc <= -12839)return "T"; if ($asc >= -12838 and $asc <= -12557)return "W"; if ($asc >= -12556 and $asc <= -11848)return "X"; if ($asc >= -11847 and $asc <= -11056)return "Y"; if ($asc >= -11055 and $asc <= -10247)return "Z"; return $so; }
如果不会 那么打包的文件里面有 extend.func.php 覆盖到对应的位置即可 include/taglib/tag.lib.php
4)打开 服务器上的 include/arc.taghtml.class.php 第169行替换成
$pinyin_title = getfirstchar($this->Fields['title']);
如果不会 那么打包的文件里面有 arc.taghtml.class.php 覆盖到对应的位置即可 include/arc.taghtml.class.php
三、使用说明:
1、进入后台“生成”,即可看到左边的“更新TAG静态”(就在更新主页、栏目、文档等功能的下方)
实现的效果如图
四 调用
1)如果想在文章详情页调用这种 静态标签化的TAG 可使用以下代码
article_article.htm 里面标签的位置替换为
{dede:field.id function='nic_arc_tag_link(@me)'/}
2) 如果想在分类列表页调用 静态标签化的TAG 可使用以下代码
[field:id function='nic_arc_tag_link(@me)'/]
3) 如果想替换现有的TAG页面 那么把 default/taglist.htm里面的代码
覆盖 list_tag.htm
文件包下载
https://files.cnblogs.com/files/baker95935/TAG%E9%9D%99%E6%80%81%E5%8C%96DEDECMS5.7SP2GBK.rar