今天在群里说要分享的内链修改代码,我来履行承诺了。
效果如
http://www.sanshu.cn/a/38.html
内链是很多 站长都重视的一个SEO的步骤,不光可以引导蜘蛛去抓取,也能在别人采集你网站内容的时候带上你的链接。
本修改支持分类或话题或分类加话题的内链。大家可以自己选择。建议大家别用分类加话题 因为处理效率比前面2者的要慢 一倍。
好了开始上代码了:
首先需要增加一个model 类。
取名为:innerlink.php 放在网站根目录的/model下
<?php /* +-------------------------------------------------------------------------- | WeCenter [#RELEASE_VERSION#] | ======================================== | by WeCenter Software | © 2011 - 2014 WeCenter. All Rights Reserved | http://www.wecenter.com | ======================================== | Support: WeCenter@qq.com | +--------------------------------------------------------------------------- */ if (!defined('IN_ANWSION')) { die; } class innerlink_class extends AWS_MODEL { public function get_category_topic_list($type=1) { $result_cache_key = 'get_category_tag_list'.$type; // AWS_APP::cache()->delete($result_cache_key); if ($result = AWS_APP::cache()->get($result_cache_key)){ return $result; } switch($type){ case 1: $sql = "SELECT `id` ,`title`,'c' as t FROM ".get_table('category'); break; case 2: $sql = " SELECT `topic_id` id ,`topic_title` title,'t' as t FROM ".get_table('topic'); break; default: $sql = "SELECT `id` ,`title`,'c' as t FROM ".get_table('category')." union SELECT `topic_id` id ,`topic_title` title,'t' as t FROM ".get_table('topic'); } if ($result = $this->query_all($sql)) { $filter = array('href','ref','ef','f'); $i=0; foreach($result as $r) { if(in_array($r['title'],$filter))continue; $resulta[$r['title']]['id'] = $r['id']; $resulta[$r['title']]['title'] = $r['title']; $resulta[$r['title']]['t'] = $r['t']; } AWS_APP::cache()->set($result_cache_key, $resulta, get_setting('cache_level_high')); return $resulta; }else{ return null; } } }第二步 修改 app/article/main.php 搜索代码 $article_info['user_info'] = $this->model('account')->get_user_info_by_uid($article_info['uid'], true); 在 这个下面写
$content = $article_info['message']; $res = $this->model('innerlink')->get_category_topic_list(1); //print_r($res); foreach($res AS $r) { $id = $r['id']; $title = $r['title']; if($r['t']=='c'){ $content = str_replace($title,"$title",$content); }else{ $content = str_replace($title,"$title",$content); } } $article_info['message'] = $content;然后就好啦。 ps:只考虑到了功能实现,代码写的不算太好,加上自己又是半吊子的php程序员,大家见谅哈。
2017-01-08 11:55