分类存档: seo

为文章创建标题搜索引擎引导,很好的seo技巧

应老总的要求,学习36qp.com的文章页面seo,我在dede系统的文章标题下创建了标题搜索引擎引导。这样可以引导用户或者爬行蜘蛛继续浏览其网站下的相关文章,增加pv
方法很简单,就是增加一系列的搜索引擎搜索该文章标题的链接,演示地址http://58w.cn/a/chess/gonggao/647.html。
在dede系统下增加如下代码即可:
在include/common.func.php下载增加下面的函数:

1
2
3
4
5
6
7
8
function sousuo($title){
    $str = '';
    $str = "<a href='http://www.baidu.com/s?wd=site:www.58w.cn ".$title."'><font color='red'>百度收录</font></a>";
    $str.= "&nbsp;<a href='http://www.google.com.hk/search?hl=zh-CN&source=hp&q=site:www.58w.cn ".$title."'><font color='blue'>谷歌收录</font></a>";
    $str.= "&nbsp;<a href='http://www.sogou.com/web?query=site:www.58w.cn ".$title."'><font color='green'>搜狗收录</font></a>";
    $str.= "&nbsp;<a href='http://www.soso.com/q?pid=s.idx&w=site:www.58w.cn+".$title."'><font color='#8E388E'>搜搜收录</font></a>";
    return $str;
}

在内容模板里使用如下代码:

1
{dede:field name='title' function='sousuo(@me)'/}

制作外链工具原理

应单位需要做了一款外链工具,以加强网站的seo。
我在这里记录一下我做这款外链工具的程序原理。
基本原理:使用ajax结合php的技术远程抓取文件,从而达到运行该文件刷链的目的。
接下来记录一下具体是怎么做的:
结构:我们需要这样几个文件:jquery-1.5.1.js,index.php,urls.php,fun.php,backdata.php。
其中,jquery-1.5.1.js大家都知道(你懂的,下载一个就行了),这里就不用多说了
index.php是工具执行的索引程序
urls.php要刷链的网址都放在这里面
fun.ph扩展函数
backdata.php是ajax的请求数据地址
下面,贴出代码:
index.php:

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
header("Content-type: text/html; charset=utf-8");
?>
<style type="text/css">
.box{ height:25px; width:550px; overflow:hidden;font-size:12px;}
.num{height:25px; width:50px; float:left; overflow:hidden; line-height:25px; text-align:center;}
.box_url{ height:25px; width:450px; float:left; overflow:hidden; line-height:25px; text-align:left;}
.box_text{ height:25px; width:50px; float:left; overflow:hidden; line-height:25px; text-align:right;}
</style>
<script type="text/javascript" src="jquery-1.5.1.js"></script>
<?php
require('fun.php');//调用扩展函数
require('urls.php');//调用需要刷链的网址
$num=count($urls); //刷链网址个数
$yuming=empty($_GET['yuming'])?'':$_GET['yuming'];//需要刷的域名
$page=empty($_GET['page'])?'':$_GET['page'];//页码
$cishu=10;//每页刷链条数
?>
<!--输出刷链的模板-->
<center>
<?php  for ($i=0;$i<$cishu;$i++){?>
<div class="box" id="link<?php echo $i;?>">请等待...</div>
<?php }?>
</center>
<!--输出刷链的模板end-->
<?php
if($page*$cishu>=$num+$cishu)$newurl=1;//判断是否将所有网址都刷过
else $newurl=0;
if(isset($yuming)&&!empty($yuming)){
    if(isset($page)){
        if(empty($page))$page='1';
        if($newurl==1)echo "<SCRIPT language=JavaScript>this.location.href='?yuming=".$yuming."&page=1';</SCRIPT>";//如果所有网址都循环刷了一遍就从头开始
        else{
            $string='';
?>
<!--执行Ajax请求数据-->
<script type="text/javascript">
$(document).ready(function(){
            <?php
            for ($i=0;$i<$cishu;$i++){
                $urlnum=($page-1)*$cishu+$i+1;
                $the_url=str_replace('{$url}',$yuming,$urls[$urlnum]);//替换域名,得到真实网址
?>

    $.post("backdata.php",{url:<?php echo '"'.$the_url.'"';?>,num:<?php echo $urlnum;?>},function(data){
        $("#link<?php echo $i;?>").html(data);
    });
<?php       }?>
});
</script>
<!--执行Ajax请求数据end-->
<?php
        }  
    }
    else exit('非法进入');
}
else exit('非法进入');
if($newurl==1){//如果所有网址都循环刷了一遍就把网址的顺序打乱一遍
    shuffle($urls);
    $urlsname='urls';
    file_put_contents($urlsname.'.php','<?php $'.$urlsname.'='.var_export($urls, true).';?>');
}
$page=$page+1;
?>
<!--10秒之后进入下一页-->
<script type="text/javascript">
$(document).ready(function(){
/*自定义倒计时10秒*/
var t = 10;//倒计时设置时间
$("#time").html(t);
function getTimes(){
    if(t>0){
        t = t - 1;
        $("#time").html(t);
    }
    if(t==0)this.location.href='?yuming=<?php echo $yuming;?>&page=<?php echo $page;?>';
}
setInterval(getTimes,1000);
});
</script>
<!--自定义倒计时10秒-->
<center>请不要关闭窗口,<span id='time' style="color:#F00;"></span> 秒后自动跳入下一页</center>
<!--10秒之后进入下一页end-->

urls.php里面的网址比较多,我贴出20个就是了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php $urls=array (
  0 => 'http://tool.liehuo.net/pr/index.php?url={$url}',
  1 => 'http://www.oumuo.cn/tool.asp?weburl={$url}',
  2 => 'http://dict.soso.com/q?sc=dict&w={$url}',
  3 => 'http://modo520.cn/dh/alexa/?domain={$url}&chkall=on&alexa=1&google=1&baidu=1&msn=1&yahoo=1&links=1&sina=1&do163=1&sohu=1&qq=1&zhongsou=1&uptimebot=1&whois=1&googlerank=1',
  4 => 'http://www.emroom.com/alexa.asp?domain={$url}&chkall=on&googlerank=1&google=1&baidu=1&msn=1&yahoo=1&yisou=1&alexa=1&sina=1&sohu=1&do163=1&qq=1&whois=1&uptimebot=1&isou=1&links=1',
  5 => 'http://www.8d.cn/s?wd={$url}&domain=8d.cn&pid=sc_nr_10032&s=R&tag=',
  6 => 'http://tool.lply.com/?url={$url}',
  7 => 'http://post.soso.com/sobar.q?op=searchpost&kw={$url}&pid=',
  8 => 'http://www.dss.cn/chajian/pr/default.asp?domain={$url}&chkall=on&googlerank=1&google=1&baidu=1&msn=1&yahoo=1&yisou=1&links=1&sina=1&sohu=1&do163=1&qq=1&zhongsou=1&uptimebot=1&whois=1&alexa=1&ip=1&keys=1',
  9 => 'http://look.515888.net/tools/baiducha/index.asp?wd={$url}&long=1',
  10 => 'http://www.0668.tv/pr/?domain={$url}&Submit=%B2%E9%D1%AF&chkall=on&googlerank=1&google=1&baidu=1&msn=1&yahoo=1&yisou=1&links=1&sina=1&sohu=1&do163=1&qq=1&zhongsou=1&uptimebot=1&whois=1&alexa=1&ip=1&keys=1',
  11 => 'http://alexa.3m2n.com/?url={$url}',
  12 => 'http://www.ok365.com/search.html?k=site%3A{$url}&area=564&s=&e=',
  13 => 'http://www.vkbbs.com/alexa.asp?url={$url}',
  14 => 'http://cnweb.search.live.com/images/results.aspx?q={$url}&FORM=BIRE',
  15 => 'http://www.robtex.com/dns/{$url}.html',
  16 => 'http://tool.163k.com/PR/?domain={$url}&chkall=on&googlerank=1&google=1&baidu=1&zhongsou=1&yahoo=1&links=1&do163=1&sohu=1&qq=1&alexa=1&whois=1',
  17 => 'http://www.pqshow.com/alexa/Index.asp?url={$url}',
  18 => 'http://www.ctbuxiu.com/alexa/Index.asp?url={$url}',
  19 => 'http://www.webchar.com/alexa/?domain={$url}&Submit=%B2%E9%D1%AF&chkall=on&googlerank=1&google=1&baidu=1&zhongsou=1&yahoo=1&links=1&do163=1&sohu=1&qq=1&alexa=1&whois=1',
  20 => 'http://www.all-list.cn/tools/indexed.do?domain={$url}'
?>

fun.php代码:

1
2
3
4
5
6
7
8
9
10
11
<?php
function curl_exe($url,$print='1'){
        $curl = curl_init(); //初始化一个 cURL 对象
        curl_setopt($curl, CURLOPT_URL, $url);//设置你需要抓取的URL    
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, $print);//设置cURL 参数,设置0,显示在网页中,设置1,不显示在网页中。     
        //综上我们就完成其基础的配置,现在执行抓取了。
        $data = curl_exec($curl); //运行cURL,请求网页
        curl_close($curl); //关闭URL请求
        return $data;
}
?>

backdata.php代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
require('fun.php');//调用扩展函数
$the_url=$_POST['url'];
$num=$_POST['num'];
$string='';
$string .= '<div class="num">['.$num.']</div><div class="box_url"><a href='."$the_url".' target="_blank">'.$the_url.'</a></div>';
$data=curl_exe($the_url);//抓取文件,运行网址
if(strlen($data)>100)$string .= '<div class="box_text">ok</div>';
else{
    $string .= '<div class="box_text">false</div>';
}
echo $string;
?>

演示地址:http://www.pk137.com:99/?yuming=58w.cn&page=1

在dede文章中添加锚文本

在上一次在文章中添加关键词的基础上,终于把文章锚文本的事情搞定了,在此记录一下
首页在文章模板中的,把body标签

1
{dede:field.body/}

用下面这段代码替换

1
{dede:field name='id' function='into_key(@me)'/}

然后在include\common.func.php文件中添加into_key等相关函数

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*增加关键词*/
function into_key($actileid){  
    //获得文章内容
    $dsql = new DedeSql(false);
    $row = $dsql->GetOne("SELECT * FROM `#@__addonarticle` WHERE `aid` = {$actileid} LIMIT 0, 1");
    $actile = $row['body'];
    //判断是否存在关键词
    $keywords=array("扎金花","炸金花","诈金花","扎金花游戏大厅","同城游戏大厅下载","梭哈","梭哈游戏","梭哈游戏下载","58w同城游");
    $keyword="&nbsp;&nbsp;<a href='http://www.58w.cn/'>"."<b>".$keywords[mt_rand(0,count($keywords)-1)]."</b>"."</a>&nbsp;&nbsp;<span>www.58w.cn<span>";
    foreach ($keywords as $k => $v){
        $is_word='';
        $keyw='';
        $keyw="<b>".$v."</b>";  
        if(strstr($actile,$keyw)){
            $is_word=1;
            continue;  
        }else $is_word=0;
    }
    //判断是否存在url
    $keyurls=array("www.58w.cn","www.sky58.com","www.yes58.net/58w","www.pk28.com");
    $keyurl="&nbsp;&nbsp;<font style='color:#fff'>".$keyurls[mt_rand(0,count($keyurls)-1)]."</font>";
    if(strstr($actile,'<span>www.58w.cn<span>'))$is_url=1;
    else $is_url=0;
    //分离文章
    $str=preg_replace('/<p(.*)>/isU','',$actile);
    $arr=explode('</p>',$str);
    $arr=array_remove_empty($arr);  
    //随机加粗文章段落
    $txtnum=mt_rand(0,count($arr)-1);
    $arr[$txtnum]='<b>'.$arr[$txtnum].'</b>';    
    //加入关键词
    if($is_word==0){
        $key=count($arr)-1;
        $arr[$key]=$arr[$key].$keyword;
    }  
    //加入url
    if($is_url==0){
        $urlnume=mt_rand(0,count($arr)-1);
        $arr[$urlnume]=$arr[$urlnume].$keyurl;
    }
    //合并文章
    foreach ($arr as $k => $v){
        $arr[$k]='<p>'.$arr[$k].'</p>';
    }
    $actile=implode('',$arr);
    //添加锚文本,以tag为准
    $actile=txt_url($actile,$row['aid']);
    //返回文章
    return $actile;
}
function txt_url($actile,$aid){
    //得到文章tags,以tid排序
    $dsql = new DedeSql(false);
    $query = "SELECT * FROM `#@__taglist` WHERE aid='$aid' order by tid asc";
    $dsql->Execute('tag',$query);
    $i=0;
    while($row = $dsql->GetArray('tag'))
    {
        $i++;
        $tags[$i]['tag'] = $row['tag'];
        $tags[$i]['tid'] = $row['tid'];
    }//print_r($tags);echo '<hr>';
    //得到相关tags随机文章id,先搜索tid靠前的tag相关文章
    $j=0;
    foreach ($tags as $k => $v) {
        $query = "SELECT * FROM `#@__taglist` WHERE `tid` = '{$v['tid']}' and aid != {$aid}";
        $dsql->SetQuery($query);
        $dsql->Execute();
        $arraid=array();
        while($row = $dsql->GetArray())
        {
            $arraid[] = $row['aid'];
        }  
        if(empty($arraid))continue;
        else{
            $j++;
            shuffle($arraid);
            $newtag[$j]['aid']=$arraid['0'];
            $newtag[$j]['tag']=$v['tag'];
            continue;
        }
       
    }//print_r($newtag);echo '<hr>';
    //得到相应文章的url访问规则和文章标题
    foreach ($newtag as $k => $v){
        $row = $dsql->GetOne("Select arc.title as title,t.typedir as dir from `#@__archives` arc left join #@__arctype t on arc.typeid=t.id where arc.id={$v['aid']}");
        $urldir = $row['dir'];
        $urltitle = $row['title'];
        $row['dir']=str_replace('{cmspath}','http://www.58w.cn',$row['dir']);
        $trueurl=$row['dir'].'/'.$v['aid'].'.html';
        $newtag[$k]['link']="<a href='{$trueurl}' title='{$urltitle}'>".$v['tag']."</a>";
    } //print_r($newtag);echo '<hr>';
    //提取超链接,图片等html标签,以免将超链接里面title或alt含有的关键词替换掉
    $pat1 = '/<a(.*)<\/a>/isU';
    $pat2 = '/<img(.*)>/isU';
    $pat3 = '/<font(.*)<\/font>/isU';
    $alink1=get_html($pat1,$actile);
    $alink2=get_html($pat2,$actile);
    $alink3=get_html($pat3,$actile);
    $alink=array_merge($alink1,$alink2,$alink3);
    foreach ($alink as $k => $v){
        $actile=str_replace($v,'/*/'.$k.'/*/',$actile);
    }
    //用锚文本替换关键词,只替换一次,只替换一个关键词
    foreach ($newtag as $k => $v){
        if(!strstr($actile,$v['tag']))continue;
        else {
            $actile=preg_replace("/{$v['tag']}/","{$v['link']}",$actile,'1');
            break;
        }
    } //print_r($alink);echo '<hr>';
    //将超链接,图片等还原
    foreach ($alink as $k => $v){
        $actile=str_replace('/*/'.$k.'/*/',$v,$actile);
    }
    return $actile;
}
/*提取超链接,图片等html标签*/
function get_html($pat,$actile){
    preg_match_all($pat, $actile, $match);
    return $match['0'];
}
/*去除空数组*/
function array_remove_empty(&$arr, $trim = true)
{
    foreach ($arr as $key => $value) {
        if (is_array($value)) {
            array_remove_empty($arr[$key]);
        } else {
            $value = trim($value);
            $value = str_replace('&nbsp;','',$value);
            if ($value == '') {
                unset($arr[$key]);
            } elseif ($trim) {
                $arr[$key] = $value;
            }
        }
    }
    $arr=array_values($arr);
    return $arr;
}

这样就实现在文章段落末尾随机添加隐藏网址,文章末尾随机关键词,以及锚文本等功能了

在dede文章中添加随机带链接关键词

在seo中需要对文章做一些特殊的改动来加强文章的收录和质量。
今天我要在在dede文章的最后一段(也可以是随机的)加上带有链接的关键词。
具体做法是:
首先,在根目录下找到include/common.func.php文件,添加个关键的函数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function into_key($actile){
    $keyword=array("扎金花","炸金花","诈金花","扎金花游戏大厅","同城游戏大厅下载","梭哈","梭哈游戏","梭哈游戏下载","58w同城游");//设置关键字
    $keyword="&nbsp;&nbsp;<a href='http://www.58w.cn/'>".$keyword[mt_rand(1,count($keyword)-1)]."</a>";//设置链接
    $str=substr($actile,strlen('<p>')+1,strlen($str)-strlen('</p>')-2);
    $arr=explode('<p>',$str);
    //if(strstr($actile,'<strong>友情链接:'))$isb=1;
    //else $isb=0;$knum='';
    foreach ($arr as $k => $v){
        if(strstr($v,'</p>'))$arr[$k]=substr($v,0,strlen($v)-strlen('</p>')-2);
        //if(strstr($v,'<strong>友情链接:'))$knum=$k;
    }
    //if($isb==1&&!empty($knum))$key=$knum-1;
    $key=count($arr)-1;
    $arr[$key]=$arr[$key].$keyword;
    foreach ($arr as $k => $v){
        $arr[$k]='<p>'.$arr[$k].'</p>';
    }
    $str=implode('',$arr);
    return $str;
}

然后,在模板文件里把内容标签替换成串代码就ok了

1
 {dede:field name='id' function='into_key(@me)'/}

如此,你以后添加的文章的最后一段都含有带链接的关键字了。
照搬这种形式,还可以在任意段落添加上相关栏目的文章等信息,使你的文章能更好的收录
例:http://www.58w.cn/a/xinwen/kexue/18247.html

使用“external nofollow”防止权重流失

今天对我们公司的一个重要的棋牌推广网站(www.58w.cn)做了seo的优化的工作,目的是指引百度蜘蛛爬行,保留首页的权重而不分散。

先讲讲我们的思路:蜘蛛从首页进入网站,指引它爬行各个栏目页面和列表页面,对内容页面不进行爬行;当蜘蛛进入列表页面或者栏目页面后,就可以让它随意爬行了;之后蜘蛛进入到文章内容页面,这时指引蜘蛛爬回首页,其他页面就不爬了;并且每个页面顶部最开始的位置都要含有带<h1>标签的网站主题名称。

在这个过程中我们要用到一个关键的html标签rel=”external nofollow”。它的作用是告诉百度蜘蛛不要爬行带有此标签的链接,从而保留了页面权重集中而没有分散。

我们只有在不想在超链接里面加上rel=”external nofollow”,百度蜘蛛就不会爬行这个链接,也就不会把权重付给这个链接了。