很多站长对于收录,就是想着,百度你快来爬我的文章,来收录我的文章,但你都没提交你的收录链接,这像极了我在知乎上看到的这个话题《为啥女朋友想让我做一件事不跟我说,让我去猜?》,看看这多气人。
![图片[1]-wordpress通过代码和宝塔自动提交百度收录,别让百度来猜](http://www.kekc.cn/wp-content/uploads/2022/05/ca043d363118.jpg)
![图片[2]-wordpress通过代码和宝塔自动提交百度收录,别让百度来猜](http://www.kekc.cn/wp-content/uploads/2022/05/5eeea080d4de.jpg)
真的非常相似,是的,我们每个站长都希望,我们的文章,百度能自己抓取,省时省力,而一些站长又不告诉百度我的链接在这或者是我的链接给你。让百度猜?今天我们就用代码和计划任务和百度《说》。
sitemap网站地图(链接在这里)
这个是将我们有用的链接,全部放到一个xml文件下,方便告诉百度,我的链接在哪里。但是还是把网站地图告诉给百度,提交给百度。
1、我们先展示代码(将下方代码复制,并保存到wordpress根目录,即可):
<?phprequire('./wp-blog-header.php');header("Content-type: text/xml");header('HTTP/1.1 200 OK');$posts_to_show = 9999999999;echo '<?xml version="1.0" encoding="UTF-8"?>';echo '<urlset xmlns="om/schemas/sitemap-mobile/1/">'?><!-- generated-on=<?php echo get_lastpostdate('blog'); ?> Diy By kekc博客(https://www.kekc.cn/)--><url><loc><?php echo get_home_url(); ?></loc><lastmod><?php $ltime = get_lastpostmodified('GMT');$ltime = gmdate('Y-m-d\TH:i:s+00:00', strtotime($ltime)); echo $ltime; ?></lastmod><changefreq>daily</changefreq><priority>1.0</priority></url><?php/* 文章页面 */$myposts = get_posts( "numberposts=" . $posts_to_show );foreach( $myposts as $post ) { ?><url><loc><?php the_permalink(); ?></loc><lastmod><?php the_time('c') ?></lastmod><changefreq>monthly</changefreq><priority>0.6</priority></url><?php } /* 文章循环结束 */ ?><?php/* 单页面 */$mypages = get_pages();if(count($mypages) > 0) {foreach($mypages as $page) { ?><url><loc><?php echo get_page_link($page->ID); ?></loc><lastmod><?php echo str_replace(" ","T",get_page($page->ID)->post_modified); ?>+00:00</lastmod><changefreq>weekly</changefreq><priority>0.6</priority></url><?php }} /* 单页面循环结束 */ ?><?php/* 博客分类 */$terms = get_terms('category', 'orderby=name&hide_empty=0' );$count = count($terms);if($count > 0){foreach ($terms as $term) { ?><url><loc><?php echo get_term_link($term, $term->slug); ?></loc><changefreq>weekly</changefreq><priority>0.8</priority></url><?php }} /* 分类循环结束 */?><?php/* 标签(可选) */$tags = get_terms("post_tag");foreach ( $tags as $key => $tag ) {$link = get_term_link( intval($tag->term_id), "post_tag" );if ( is_wp_error( $link ) )return false;$tags[ $key ]->link = $link;?><url><loc><?php echo $link ?></loc><changefreq>monthly</changefreq><priority>0.4</priority></url><?php } /* 标签循环结束 */ ?></urlset><?php require('./wp-blog-header.php'); header("Content-type: text/xml"); header('HTTP/1.1 200 OK'); $posts_to_show = 9999999999; echo '<?xml version="1.0" encoding="UTF-8"?>'; echo '<urlset xmlns="om/schemas/sitemap-mobile/1/">' ?> <!-- generated-on=<?php echo get_lastpostdate('blog'); ?> Diy By kekc博客(https://www.kekc.cn/)--> <url> <loc><?php echo get_home_url(); ?></loc> <lastmod><?php $ltime = get_lastpostmodified('GMT');$ltime = gmdate('Y-m-d\TH:i:s+00:00', strtotime($ltime)); echo $ltime; ?></lastmod> <changefreq>daily</changefreq> <priority>1.0</priority> </url> <?php /* 文章页面 */ $myposts = get_posts( "numberposts=" . $posts_to_show ); foreach( $myposts as $post ) { ?> <url> <loc><?php the_permalink(); ?></loc> <lastmod><?php the_time('c') ?></lastmod> <changefreq>monthly</changefreq> <priority>0.6</priority> </url> <?php } /* 文章循环结束 */ ?> <?php /* 单页面 */ $mypages = get_pages(); if(count($mypages) > 0) { foreach($mypages as $page) { ?> <url> <loc><?php echo get_page_link($page->ID); ?></loc> <lastmod><?php echo str_replace(" ","T",get_page($page->ID)->post_modified); ?>+00:00</lastmod> <changefreq>weekly</changefreq> <priority>0.6</priority> </url> <?php }} /* 单页面循环结束 */ ?> <?php /* 博客分类 */ $terms = get_terms('category', 'orderby=name&hide_empty=0' ); $count = count($terms); if($count > 0){ foreach ($terms as $term) { ?> <url> <loc><?php echo get_term_link($term, $term->slug); ?></loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url> <?php }} /* 分类循环结束 */?> <?php /* 标签(可选) */ $tags = get_terms("post_tag"); foreach ( $tags as $key => $tag ) { $link = get_term_link( intval($tag->term_id), "post_tag" ); if ( is_wp_error( $link ) ) return false; $tags[ $key ]->link = $link; ?> <url> <loc><?php echo $link ?></loc> <changefreq>monthly</changefreq> <priority>0.4</priority> </url> <?php } /* 标签循环结束 */ ?> </urlset><?php require('./wp-blog-header.php'); header("Content-type: text/xml"); header('HTTP/1.1 200 OK'); $posts_to_show = 9999999999; echo '<?xml version="1.0" encoding="UTF-8"?>'; echo '<urlset xmlns="om/schemas/sitemap-mobile/1/">' ?> <!-- generated-on=<?php echo get_lastpostdate('blog'); ?> Diy By kekc博客(https://www.kekc.cn/)--> <url> <loc><?php echo get_home_url(); ?></loc> <lastmod><?php $ltime = get_lastpostmodified('GMT');$ltime = gmdate('Y-m-d\TH:i:s+00:00', strtotime($ltime)); echo $ltime; ?></lastmod> <changefreq>daily</changefreq> <priority>1.0</priority> </url> <?php /* 文章页面 */ $myposts = get_posts( "numberposts=" . $posts_to_show ); foreach( $myposts as $post ) { ?> <url> <loc><?php the_permalink(); ?></loc> <lastmod><?php the_time('c') ?></lastmod> <changefreq>monthly</changefreq> <priority>0.6</priority> </url> <?php } /* 文章循环结束 */ ?> <?php /* 单页面 */ $mypages = get_pages(); if(count($mypages) > 0) { foreach($mypages as $page) { ?> <url> <loc><?php echo get_page_link($page->ID); ?></loc> <lastmod><?php echo str_replace(" ","T",get_page($page->ID)->post_modified); ?>+00:00</lastmod> <changefreq>weekly</changefreq> <priority>0.6</priority> </url> <?php }} /* 单页面循环结束 */ ?> <?php /* 博客分类 */ $terms = get_terms('category', 'orderby=name&hide_empty=0' ); $count = count($terms); if($count > 0){ foreach ($terms as $term) { ?> <url> <loc><?php echo get_term_link($term, $term->slug); ?></loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url> <?php }} /* 分类循环结束 */?> <?php /* 标签(可选) */ $tags = get_terms("post_tag"); foreach ( $tags as $key => $tag ) { $link = get_term_link( intval($tag->term_id), "post_tag" ); if ( is_wp_error( $link ) ) return false; $tags[ $key ]->link = $link; ?> <url> <loc><?php echo $link ?></loc> <changefreq>monthly</changefreq> <priority>0.4</priority> </url> <?php } /* 标签循环结束 */ ?> </urlset>
2、告诉百度
先https://ziyuan.baidu.com/注册账户,新增站点,验证站点,最后提交sitemap。
![图片[3]-wordpress通过代码和宝塔自动提交百度收录,别让百度来猜](http://www.kekc.cn/wp-content/uploads/2022/05/d2b5ca33bd97-6.png)
比如我是将代码保存到我的根目录下的sitemap.php。
然后我提交的链接就是https://www.kekc.cn/sitemap.php
api定时提交(链接给百度)
1、告诉百度,这么多网址,你还没收录呢,并且网址给百度。
代码:
<?phprequire 'wp-load.php';$url="";//文章$array=get_posts( "numberposts=-1");foreach ($array as $post) {$url.=get_permalink().',';}//页面$mypages = get_pages();if(count($mypages) > 0) {foreach($mypages as $page) {$url.=get_page_link($page->ID).',';}}//文章分类$terms = get_terms('category', 'orderby=name&hide_empty=0' );$count = count($terms);if($count > 0){foreach ($terms as $term) {$url.=get_term_link($term, $term->slug).',';}}//文章标签$tags = get_terms("post_tag");foreach ( $tags as $key => $tag ) {$link = get_term_link( intval($tag->term_id), "post_tag" );if ( is_wp_error( $link ) )return false;$tags[ $key ]->link = $link;$url.=$link.',';}$urls = explode(',', $url);function gotobaidu($urls,$api){$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);return $result;}$api = 'http://data.zz.baidu.com/urls?site=https://www.kekc.cn&token=dPsrlxzzTBwV5Stq';$res = gotobaidu($urls,$api);echo $res;?><?php require 'wp-load.php'; $url=""; //文章 $array=get_posts( "numberposts=-1"); foreach ($array as $post) { $url.=get_permalink().','; } //页面 $mypages = get_pages(); if(count($mypages) > 0) { foreach($mypages as $page) { $url.=get_page_link($page->ID).','; } } //文章分类 $terms = get_terms('category', 'orderby=name&hide_empty=0' ); $count = count($terms); if($count > 0){ foreach ($terms as $term) { $url.=get_term_link($term, $term->slug).','; } } //文章标签 $tags = get_terms("post_tag"); foreach ( $tags as $key => $tag ) { $link = get_term_link( intval($tag->term_id), "post_tag" ); if ( is_wp_error( $link ) ) return false; $tags[ $key ]->link = $link; $url.=$link.','; } $urls = explode(',', $url); function gotobaidu($urls,$api){ $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); return $result; } $api = 'http://data.zz.baidu.com/urls?site=https://www.kekc.cn&token=dPsrlxzzTBwV5Stq'; $res = gotobaidu($urls,$api); echo $res; ?><?php require 'wp-load.php'; $url=""; //文章 $array=get_posts( "numberposts=-1"); foreach ($array as $post) { $url.=get_permalink().','; } //页面 $mypages = get_pages(); if(count($mypages) > 0) { foreach($mypages as $page) { $url.=get_page_link($page->ID).','; } } //文章分类 $terms = get_terms('category', 'orderby=name&hide_empty=0' ); $count = count($terms); if($count > 0){ foreach ($terms as $term) { $url.=get_term_link($term, $term->slug).','; } } //文章标签 $tags = get_terms("post_tag"); foreach ( $tags as $key => $tag ) { $link = get_term_link( intval($tag->term_id), "post_tag" ); if ( is_wp_error( $link ) ) return false; $tags[ $key ]->link = $link; $url.=$link.','; } $urls = explode(',', $url); function gotobaidu($urls,$api){ $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); return $result; } $api = 'http://data.zz.baidu.com/urls?site=https://www.kekc.cn&token=dPsrlxzzTBwV5Stq'; $res = gotobaidu($urls,$api); echo $res; ?>
修改56行api为自己的,也就是“$api = ‘http://data.zz.baidu.com/urls?site=https://www.kekc.cn&token=dPsrlxzzTBwV5Stq’;”这一句。这一句在https://ziyuan.baidu.com/下,修改网址就行,如图:
![图片[4]-wordpress通过代码和宝塔自动提交百度收录,别让百度来猜](http://www.kekc.cn/wp-content/uploads/2022/05/d2b5ca33bd97-7.png)
我们复制代码保存为PHP并且保存在wordpress根目录。比如我的文件保存在wordpress根目录1.php,我访问https://www.kekc.cn/1.php一次,就给了百度一次我的链接。
2、定时给百度一次链接(定时提交)
上面我们不是实现访问一次就给了百度一次链接嘛?我们通过宝塔计划任务,就能定时给百度我的链接。比如我的:
![图片[5]-wordpress通过代码和宝塔自动提交百度收录,别让百度来猜](http://www.kekc.cn/wp-content/uploads/2022/05/d2b5ca33bd97-8.png)
上面的是两个东西,别搞混了。文章并非转载属于KEKC博客(www.kekc.cn)原创文章,转载请留链接。
© 版权声明
THE END
暂无评论内容