
随着人们将越来越多的时间放在手机上,以前只在电脑上才能完成的购物、聊天、信息获取等行为越来越倾向于移动手机上了。手机网民的增多,巨大的流量又会形成“倒逼”压力,让之前不关注、不在乎手机流量的网站不得不考虑一下移动搜索上的排名。移动搜索优化给部落的直观感受就是已经有不少的朋友留言要求开发一个部落博客的手机主题,因为现在的PC主题在手机上浏览并不是很方便。从百度的角度来看,百度现在正在发力移动搜索,尤其是在改善移动搜索体验不断下功夫,近期还传出百度移动搜索要取消PC网页收录。原标题:移动搜索优化SEO-用PHP自动生成百度开放适配Sitemap文件提升手机站排名百度开放适配Sitemap不同于我们平常所说的网站地图Sitemap,百度开放适配Sitemap里面是PC页—手机页的对应关系,例如对应移动页面,百度会在移动搜索中将原PC页结果替换为对应的手机页结果。提交百度开放适配Sitemap对于一些已经在百度PC搜索中有着良好排名的网站十分重要,它可以最快实现将PC网页搜索结果转化为移动搜索结果,而不是在移动搜索中经历漫长的权重提升过程,尤其是未来移动流量不可估量,提前做好移动搜索SEO服务对未来有着至关重要的意义。PC网站的URL多如牛毛,按照百度开放适配Sitemap文件格式要求文件描述url级别的PC页与手机页的对应关系,手动写肯定不行。本篇文章就来分享一下“张戈博客”开发的用PHP自动生成百度开放适配Sitemap文件的方法,一劳永逸。该方法同样适用于360移动适配服务。一、生成百度开放适配Sitemap文件前准备1、你需要一个PC网站的手机版本,对于Wordpress可以直接安装一个Wordpress手机版本的主题。二、自动生成开放适配Sitemap的PHP代码1、适用于百度开放适配Sitemap的PHP代码:
- <?php
- require('./wp-blog-header.php');
- header("Content-type: text/xml");
- header('HTTP/1.1 200 OK');
- $posts_to_show = 1000; //限制最大生成1000篇
- echo '<?xml version="1.0" encoding="UTF-8"?>';
- echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns=http://www.sitemaps.org/schemas/sitemap/0.9
- xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
- ?>
- <url>
- <loc>http://zhangge.net</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>
- <data>
- <display>
- <!-- 以下三种版式,请根据实际的手机站版式选择 –>
- <html5_url>http://m.zhangge.net</html5_url>
- <wml_url>http://m.zhangge.net</wml_url>
- <xhtml_url>http://m.zhangge.net</xhtml_url>
- </display>
- </data>
- </url>
- <?php
- header("Content-type: text/xml");
- $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>
- <data>
- <display>
- <!-- 以下三种版式,请根据实际手机站版式选择 –>
- <html5_url><?php echo str_replace("zhangge.net","m.zhangge.net",the_sitemaplink()); ?></html5_url>
- <wml_url><?php echo str_replace("zhangge.net","m.zhangge.net",the_sitemaplink()); ?></wml_url>
- <xhtml_url><?php echo str_replace("zhangge.net","m.zhangge.net",the_sitemaplink()); ?></xhtml_url>
- </display>
- </data>
- </url>
- <?php } ?>
- </urlset>
- <?php
- require('./wp-blog-header.php');
- header("Content-type: text/txt");
- header('HTTP/1.1 200 OK');
- $posts_to_show = 1000; //限制最大生成1000篇
- ?>
- http://zhangge.net<?php echo " "; ?>http://m.zhangge.net<?php echo " "; ?>
- <?php
- header("Content-type: text/txt");
- $myposts = get_posts( "numberposts=" . $posts_to_show );
- foreach( $myposts as $post ) { ?>
- <?php the_permalink(); ?><?php echo " "; ?><?php echo str_replace("zhangge.net","m.zhangge.net",the_sitemaplink()); ?><?php echo " "; ?>
- <?php } ?>
- /** 开放适配相关函数 **/
- function the_sitemaplink() {
- return esc_url( apply_filters( 'the_permalink', get_permalink() ) );
- }

- <Files ~ "^.(htaccess|htpasswd)$">
- deny from all
- </Files>
- RewriteEngine on
- RewriteCond %{HTTP_HOST} ^(www\.zhangge\.net)(:80)?
- RewriteRule ^(.*) http://zhangge.net/$1
- #sitemap-shipei-start
- RewriteRule ^(sitemap_baidu_sp)\.xml$ $1.php
- RewriteRule ^(sitemap_360_sp)\.txt$ $1.php
- #sitemap-shipei-end
- order deny,allow