移动适配xml地图

1、制作xmlmap_sp.php文件,通过ftp上传到网站根目录下。


<?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">';
?>
<!-- generated-on=<?php echo get_lastpostdate('blog'); ?> -->
 <url>
 <loc><?php echo 'http://'.$_SERVER['HTTP_HOST']; ?></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><?php echo 'http://'.$_SERVER['HTTP_HOST']; ?></html5_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 the_permalink(); ?></html5_url>
         </display>
         </data>
    </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); ?></lastmod>
      <changefreq>monthly</changefreq>
      <priority>0.6</priority>
      <data>
         <display>
           <html5_url><?php echo get_page_link($page->ID); ?></html5_url>
         </display>
         </data>
  </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>
      <data>
         <display>
           <html5_url><?php echo get_term_link($term, $term->slug); ?></html5_url>
         </display>
      </data>
  </url>
<?php }} /* 分类循环结束 */?> 
</urlset>

默认限制1000篇文章,如需调整修改第5行的数值即可;
根据网站实际声明,将代码中标签替换成相应地图版式,以下三种网站地图版式,选择一种即可:


<!— html5版式 -->
<html5_url></html5_url>
<!— wml版式 -->
<wml_url></wml_url>
<!— xhtml版式(常见版式) -->
<xhtml_url></xhtml_url>
参考如下声明,对应一下网站的版式:
HTML5版式声明:
<!DOCTYPE HTML>
WML版式声明:
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
XHTML版式声明:
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

2、设置url转发规则文件,设置方法同上方xml版站点地图制转发规则一致,对应修改文件名称即可。
然后百度提交地图地址就是了ok.
以上这样WordPress网站地图制作地图就做好了,赶紧丢掉插件使用代码版的WordPress网站地图制作吧。