文章首发于:http://mwhls.top/226.html
新的更新内容请到mwhls.top查看。
如果没有图片请到上方的文章首发页面查看。
本文提供PHPAPI与sitemap的使用示例。但API-PHP的代码推荐配套一个爬取网站网址的代码使用,不然效率不如手动提交高。sitemap部分的代码只适用于wordpress网站,但提交方法一样。
百度收录连接:https://ziyuan.baidu.com/linksubmit/index
API-PHP推送使用示例
1.复制百度收录内的php推送示例中的全部代码,建立一个baiduapi.php的文件,将内容粘贴进去保存。
2.将http://www.example.com/1.html
修改为想要推送的连接,如需推送多个,按照以下格式修改,符号均需为英文
array(
'连接地址1',
'连接地址2',
)
3.将文件上传至网站根目录,输入域名/baiduapi.php
打开,以本站为例,网站根目录在/wwwroot/中,因此将baiduapi.php上传至/wwwroot/内,输入mwhls.top/baiduapi.php
打开。
4.打开后如出现以下代码或类似代码即成功,如提示"error":401,可百度相关错误解决。
{ "remain":2998, "success":2, }
sitemap使用示例
0.附录代码仅适用于wordpress网站。
1.创建一个sitemap.php文件,将文章末尾代码复制进去。
2.将文件上传至WordPress安装目录,输入域名/wordpress/sitemap.php
打开,以本站为例,WordPress安装目录在/wwwroot/wordpress/中,因此将sitemap.php上传至/wwwroot/wordpress/内,输入mwhls.top/wordpress/sitemap.php
打开。打开后会出现自己网页各页面的信息,即成功。
3.将地址复制进百度收录中sitemap的文本框内即可。以本站为例,将mwhls.top/wordpress/sitemap.php
粘贴进sitemap的文本框内,点击提交,等待几天即可在该页面看到提交情况。
sitemap.php代码(代码提供:学做网站论坛):
直接下载:https://mwhls.lanzous.com/igLjKf0wc5e,下载完需将txt改为php格式。
<?php
require('./wp-blog-header.php');
header("Content-type: text/xml");
header('HTTP/1.1 200 OK');
$posts_to_show = 1000;
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">'
?>
<!-- generated-on=<?php echo get_lastpostdate('blog'); ?> Diy By 学做网站论坛(https://www.xuewangzhan.net/)-->
<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>