分享

移动SEO分享:php自动提交复合型Sitemap到百度搜索 | 张戈博客

 看见就非常 2014-08-08

导读:本文分享的是移动sitemap协议说明及生成复合型sitemap的方法。所谓复合型就是指一个sitemap.xml既包含了pc页,也包含了mobile页!一旦提交,双管齐下,同时搞定了结构化数据和移动开放适配!而且此方法适用于任何wordpress建站的网站,包括响应式亦可提交带响应式标识的sitemap!所以,网站是响应式的童鞋也就别在那“得瑟”你的响应式多么多么的高大上了!当然,如果你不在乎SEO那也可以不用浪费时间了。


 

不久前,张戈博客曾分享了《移动搜索SEO分享:PHP自动生成百度开放适配及360移动适配专用的Sitemap文件》,不管有没有人用,反正我用的很惬意,此文也被免费资源部落(freehao123.com)重新整理转载,反响还不错!

就在前天,惊喜的收到了期盼已久的百度sitemap邀请通知:

文章《移动SEO分享:php自动提交复合型Sitemap到百度搜索》中的图片-来自张戈博客的博客建设分类 第1张

文章《移动SEO分享:php自动提交复合型Sitemap到百度搜索》中的图片-来自张戈博客的博客建设分类 第2张

虽说,这功能在内测的时候随便用,但是很多新站都没赶上那一波,暂时都处于邀请状态:

文章《移动SEO分享:php自动提交复合型Sitemap到百度搜索》中的图片-来自张戈博客的博客建设分类 第3张

我在收到邀请通知后,迫不及待地提交了一直在冷板凳坐着的sitemap.xml!

然而不经意间,我在这个页面发现了新大陆:

文章《移动SEO分享:php自动提交复合型Sitemap到百度搜索》中的图片-来自张戈博客的博客建设分类 第4张

赶紧点开看了看:http://zhanzhang.baidu.com/wiki/93#03

三、什么是移动Sitemap协议,如何提交Sitemap到移动搜索?

百度推出了移动Sitemap协议,用于将网址提交给移动搜索收录。百度移动Sitemap协议是在标准Sitemap协议基础上制定的,增加了<mobile:mobile/>标签,它有三种取值:

  • <mobile:mobile/> :移动网页

  • <mobile:mobile type="mobile"/> :移动网页      

  • <mobile:mobile type="autoadapt"/>:自适配网页,适用于同一网址页面,会随设备不同改变展现的情况。        

  • 无该标签表示PC的网页

下方样例相当于向百度移动搜索提交了一个移动网页:http://m./index.html,向PC搜索提交了一个传统网页:http://www./index.html,同时向移动搜索和PC搜索提交了一个自适配网页http://www./autoadapt.html:

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <urlset xmlns="http://www./schemas/sitemap/0.9"
  3. xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">
  4. <url>
  5. <loc>http://m./index.html</loc>
  6. <mobile:mobile type="mobile"/>
  7. <lastmod>2009-12-14</lastmod>
  8. <changefreq>daily</changefreq>
  9. <priority>0.8</priority>
  10. </url>
  11. <url>
  12. <loc>http://www./index.html</loc>
  13. <lastmod>2009-12-14</lastmod>
  14. <changefreq>daily</changefreq>
  15. <priority>0.8</priority>
  16. </url>
  17. <url>
  18. <loc>http://www./autoadapt.html</loc>
  19. <mobile:mobile type="autoadapt"/>
  20. <lastmod>2009-12-14</lastmod>
  21. <changefreq>daily</changefreq>
  22. <priority>0.8</priority>
  23. </url>
  24. </urlset>

 

仔细看了下xml代码及百度移动sitemap协议说明,发现原来sitemap可以同时提交pc页和mobile页,如果是自适应网站还可以使用自适应标识:<mobile:mobile type="autoadapt"/>,具体请细看上方引用说明。

再对比了下我上次写的那个开放适配的php代码,10分钟不到就搞定了这个php!

下面分享php源代码:

  1. <?php
  2. require('./wp-blog-header.php');
  3. header("Content-type: text/xml");
  4. header('HTTP/1.1 200 OK');
  5. $posts_to_show = 1000; // 获取文章数量
  6. echo '<?xml version="1.0" encoding="UTF-8"?>';
  7. echo '<urlset xmlns="http://www./schemas/sitemap/0.9"';
  8. echo 'xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">'
  9. ?>
  10. <--PC页面地址,实际使用请务必删除此行注释-->
  11.   <url>
  12.       <loc>http:///</loc>
  13.       <lastmod><?php $ltime = get_lastpostmodified(GMT);$ltime = gmdate('Y-m-d\TH:i:s+00:00', strtotime($ltime)); echo $ltime; ?></lastmod>
  14.       <changefreq>daily</changefreq>
  15.       <priority>1.0</priority>
  16.   </url>
  17. <--mobile页面地址,实际使用请务必删除此行注释-->
  18.   <url>
  19.       <loc>http://m./</loc>
  20.       <mobile:mobile type="mobile"/>
  21.       <lastmod><?php $ltime = get_lastpostmodified(GMT);$ltime = gmdate('Y-m-d\TH:i:s+00:00', strtotime($ltime)); echo $ltime; ?></lastmod>
  22.       <changefreq>daily</changefreq>
  23.       <priority>1.0</priority>
  24.   </url>
  25. <--自适应页面地址,实际使用请务必删除此行注释-->
  26.   <url>
  27.       <loc>http://m./</loc>
  28.      <mobile:mobile type="autoadapt"/>
  29.       <lastmod><?php $ltime = get_lastpostmodified(GMT);$ltime = gmdate('Y-m-d\TH:i:s+00:00', strtotime($ltime)); echo $ltime; ?></lastmod>
  30.       <changefreq>daily</changefreq>
  31.       <priority>1.0</priority>
  32.   </url>
  33. <?php
  34. header("Content-type: text/xml");
  35. $myposts = get_posts( "numberposts=" . $posts_to_show );
  36. foreach( $myposts as $post ) { ?>
  37. <--PC页面地址,实际使用请务必删除此行注释-->
  38.   <url>
  39.       <loc><?php the_permalink(); ?></loc>
  40.       <lastmod><?php the_time('c') ?></lastmod>
  41.       <changefreq>monthly</changefreq>
  42.       <priority>0.6</priority>
  43.     </url>
  44. <--mobile页面地址,实际使用请务必删除此行注释-->
  45.   <url>
  46.       <loc><?php echo str_replace("","m.",the_sitemaplink()); ?></loc>
  47.       <mobile:mobile type="mobile"/>
  48.       <lastmod><?php the_time('c') ?></lastmod>
  49.       <changefreq>monthly</changefreq>
  50.       <priority>0.6</priority>
  51.     </url>
  52. <--自适应页面地址,实际使用请务必删除此行注释-->
  53.   <url>
  54.       <loc><?php the_permalink(); ?></loc>
  55.       <mobile:mobile type="autoadapt"/>
  56.       <lastmod><?php the_time('c') ?></lastmod>
  57.       <changefreq>monthly</changefreq>
  58.       <priority>0.6</priority>
  59.     </url>
  60. <?php } // end foreach ?>
  61. </urlset>

 

使用说明:

①、必须收到了百度sitemap提交权限的邀请后才能使用,当然你也可以放到根目录,弄个链接等蜘蛛自己爬;

②、如果是自适应的网站,仅需要保留 <--自适应页面地址,实际使用请务必删除此注释-->的<url>部分即可;

③、如果是自适应网站,请删除 <--自适应页面地址,实际使用请务必删除此注释-->的<url>部分;

Ps:所谓<url>部分,就是如代码中48~55行之间的类似单元内容,还不理解请多吃点“灵泛得乐”胶囊!

④、此代码只提交了文章页面,如果介意的话,可以仅保留mobile页面,去提交移动sitemap即可,pc页面可另行使用插件生成更完整的sitemap.xml。

目前张戈博客就是用的这个方法,同时向百度提交2种sitemap.xml:

文章《移动SEO分享:php自动提交复合型Sitemap到百度搜索》中的图片-来自张戈博客的博客建设分类 第5张

⑤、由于篇幅有限,就不复述其他相同的使用说明了!实际使用,请务必参考《移动搜索SEO分享:PHP自动生成百度开放适配及360移动适配专用的Sitemap文件》中的使用方法,比如伪静态、添加function函数等。

写在最后:个人觉得提交这个sitemap会比做开放适配的效果好得多!当然,前提是你的域名已开通了百度站长平台的sitemap提交功能才可以用。已有权限的童鞋赶紧试试看吧!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多