QQ在线咨询在线咨询帮做网络积累了丰富的项目经验,聚集了一批资深专业人才,售后服务一流,内业好评不断,是一家专业的网站建设服务商。微信:专业的网站建设服务商。微信:网站建设地图 | 城市分站

织梦当前文档内容自动关联tag标签做内链

时间:2020-11-06 16:11:04作者:网站建设工程师来源:帮做网络浏览量:0

导  读:织梦当前文档内容自动关联tag标签做内链 最终效果 实现教程 1、后台-系统-核...
织梦当前文档内容自动关联tag标签做内链

最终效果

实现教程

1、后台-系统-核心设置-关键字替换,选择【

2、后台-系统-其他选项-关键词替换次数,填【1】或者【0

1:表示文档内容里有多个关键词,只让1个是内链

0:表示文档内容里有多个关键词,都是内链

根据自己的需要填

3、打开 /include/arc.archives.class.php 找到,大概在1187行至1241行,整个函数

function ReplaceKeyword($kw,&$body)
{
	...中间代码省略
}
  • 1
  • 2
  • 3
  • 4

整个改成

function ReplaceKeyword($kw,&$body)
{
	global $cfg_replace_num;
	$search = "/(alt\s*=\s*|title\s*=\s*|src\s*=\s*)[\"|\'](.+?)[\"|\']/is";
	$body = preg_replace_callback($search, array('Archives', '_base64_encode'), $body);
	$addsql = '';
	if(isset($this->Fields['tags']) && !empty($this->Fields['aid']))
	{
		$this->dsql->SetQuery("SELECT tid FROM `dede_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) ";
		}
		if($addsql=='') return $body;
	}
	$query = "SELECT * FROM `dede_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])."\"";
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55

如图

4、完成,动态的直接看效果,静态的记得重新生成文档看效果


转载请注明出处:网站首页> 知识学堂 > dedecms仿站 > 织梦当前文档内容自动关联tag标签做内链