📖SEO网站优化(2):站长的添加

这篇文章教你如何将自己的网站添加到百度中,这样可以加快网站收录的速度,还有主动推送文章与蜘蛛爬取网站地图

百度站长,添加网站

百度站长链接:https://ziyuan.baidu.com/site

1:点击’添加站长’
2:选择协议头与输入网址
3:选择你所做的站点的内容
4:选择验证,验证即可

提交地图

重要3点如下:
SEO网站优化(2):站长的添加插图
1:将自己的网站地图提交到百度站长,却确认提交状态为正常(抓取时间有些慢)
SEO网站优化(2):站长的添加插图1
2:抓取诊断,查看自己网站是否被百度抓取正常
SEO网站优化(2):站长的添加插图2

主动推送

查看站长token
SEO网站优化(2):站长的添加插图3

织梦模板主动推送文件,在根目录创建baidutui.php并将下列代码写入php,修改对应代码,并在宝塔上设置定时访问url:http://你的网址/baidutui.php即可

<?php
require_once ("include/common.inc.php");
require_once "include/arc.partview.class.php";
require_once('include/charset.func.php');
$year = date("Y");
$month = date("m");
$day = date("d");
$dayBegin = mktime(0,0,0,$month,$day,$year);//当天开始时间戳
$dayEnd = mktime(23,59,59,$month,$day,$year);//当天结束时间戳 
$query = "SELECT arch.id,types.typedir FROM dede_arctype as types inner join dede_archives as arch on types.id=arch.typeid where pubdate<".$dayEnd." AND pubdate>".$dayBegin."";
//echo $query;
$urls="";			
$dsql->Execute('arch.id,types.typedir',$query);
while($row = $dsql->GetArray('arch.id,types.typedir'))
{
	$urls.="网站地址".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".",";	//这里需要填写你的网站地址
}
$urls=substr($urls,0,-1);
$urls	= explode(",",$urls);
$api = '站长token';//这里需要填写你的站长token
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("\n", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;
?>

帝国推送文件,在根目录创建maps.php与run.php并将下列代码写入php,修改对应代码,并在宝塔上设置定时访问url:http://你的网址/run.php即可
run.php 无需修改,maps.php 将自己的网站地图与站长token修改即可
run.php

//run.php
<?php
set_time_limit(0);

ini_set('memory_limit', '2048M');
ini_set(
    'user_agent',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'
);
date_default_timezone_set('Asia/Shanghai');
function push($api, $urls)
{
    $ch = curl_init();

    $options = array(
        CURLOPT_URL => $api,
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POSTFIELDS => implode("\n", $urls),
        CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
    );
    curl_setopt_array($ch, $options);
    $response = curl_exec($ch);
    curl_close($ch);
    $msg = (false !== strpos($response, 'success')) ? '成功' : '失败';
    // echo "$api => $msg => $response\n";
}
function rockets()
{
    $maps = include(__DIR__ . '/maps.php');
    foreach ($maps as $sitemap => $api) {
        $urls = array();
        preg_match_all('/<loc>(.*?)<\/loc>/', file_get_contents($sitemap), $result);
        foreach ($result[1] as $url) {
            if (false !== strpos($url, '.html')) { # 只推送内页
                $urls[] = $url;
                if (count($urls) >= 50) {
                    push($api, $urls);
                    $urls = array(); # 每次推 50
                }
            }
        }
        if (count($urls) > 1) {
            push($api, $urls); # 推送末尾的
        }
        echo "$sitemap => 推送完成\n";
    }
}
rockets();

maps.php

<?php
return array(
    '这里是网站地图的链接' => '站长token',
);

WordPress推送,这里用的是插件推送,当你发布新文章时则会自动推送,插件搜索zhanzhangb-baidu-submit,如下输入站长token即可
SEO网站优化(2):站长的添加插图4

标签

🧐发表评论

您必须启用javascript才能在此处查看验证码