实现教程
1、后台-系统-核心设置-关键字替换,选择【是】
(此图片来源于网络,如有侵权,请联系删除! )
2、后台-系统-其他选项-关键词替换次数,填【1】或者【0】
1:表示文档内容里有多个关键词,只让1个是内链
0:表示文档内容里有多个关键词,都是内链
根据自己的需要填
(此图片来源于网络,如有侵权,请联系删除! )
3、打开 /include/arc.archives.class.php 找到,大概在1187行至1241行,整个函数
function ReplaceKeyword($kw,&$body) { ...中间代码省略 } |
整个改成
function ReplaceKeyword($kw,&$body) { global $cfg_replace_num; //如果当前文档没有tag直接不内链,需要匹配所有tag的话,删除下面行 if(GetTags($this->Fields['aid']) == '') return $body; $search = "/(alt\s*=\s*|title\s*=\s*|src\s*=\s*)[\"|\'](.+?)[\"|\']/is"; $body = preg_replace_callback($search, array('Archives', '_base64_encode'), $body); $addsql = ''; $this->dsql->SetQuery("SELECT tid FROM `58pic_taglist` WHERE aid = '{$this->Fields['aid']}' "); $this->dsql->Execute(); $ids = ''; while($row = $this->dsql->GetArray()) { $ids .= ( $ids=='' ? $row['tid'] : ','.$row['tid'] ); } if($ids != '') { $addsql = " WHERE id IN($ids) "; } $query = "SELECT * FROM `58pic_tagindex` $addsql ORDER BY addtime DESC"; $this->dsql->SetQuery($query); $this->dsql->Execute(); $linkdatas = array(); while($row = $this->dsql->GetArray()) { $row['keyword'] = $row['tag']; $row['rpurl'] = $cfg_cmsurl."/tags.php?/".urlencode($row['tag'])."/"; $linkdatas[] = $row; } if($linkdatas) { $word = $replacement = array(); foreach($linkdatas as $v) { $word0[] = "/<a[^>]*>{$v['keyword']}<\/a>/is"; $word1[] = '/'.$v['keyword'].'/is'; $word2[] = $v['keyword']; $replacement[] = '<a href="'.$v['rpurl'].'" target="_blank">'.$v['keyword'].'</a>'; } if($cfg_replace_num) { $body = preg_replace($word0, $word2, $body, $cfg_replace_num); $body = preg_replace($word1, $replacement, $body, $cfg_replace_num); } else { $body = str_replace($word2, $replacement, $body); } } $body = preg_replace_callback($search, array('Archives', '_base64_decode'), $body); return $body; } function _base64_encode($matches) { return $matches[1]."\"".base64_encode($matches[2])."\""; } function _base64_decode($matches) { return $matches[1]."\"".base64_decode($matches[2])."\""; } |
如图
(此图片来源于网络,如有侵权,请联系删除! )
如果你的tag链接是伪静态或者静态链接,把里面的
$cfg_cmsurl."/tags.php?/".urlencode($row['tag'])."/";
改成与include/taglib/tag.lib.php里面的一致即可
(此图片来源于网络,如有侵权,请联系删除! )
4、完成,动态的直接看效果,静态的记得重新生成文档看效果
免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)