wordpress建立html和xml百度网站地图 代码插件双方法

引言:此文由子域名转移而来,因为细微强迫症和放弃子域名而不舍得完全丢弃,所以将会逐步第二次转移文章到主域名上来,二者主题(阿里白秀和D8)均来自大前端,追求完美的同时有一丝小懒,主题就不换了,D8主题用起来挺好。

/tmp/phpqigCst

为了给wordpress网站减肥,对于网站地图也有非插件建立html和xml的方法。

1、html网站地图

①先下载html网站地图模板文件,并放于主题目录下。

下载地址:

百度网盘下载
千脑网盘下载

②wordpress后台新建页面,模板选择“站点地图”,生成的链接即为html网站地图地址,可以把它放于网页任何位置。

2、xml网站地图

①在你的网站根目录新建xmlmap.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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  8. xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
  9. ?>
  10. <!-- generated-on=<?php echo get_lastpostdate('blog'); ?>-->
  11.   <url>
  12.       <loc>http://www.2zzt.com/</loc>
  13.       <lastmod><?php echo get_lastpostdate('blog'); ?></lastmod>
  14.       <changefreq>daily</changefreq>
  15.       <priority>1.0</priority>
  16.   </url>
  17. <?php
  18. header("Content-type: text/xml");
  19. $myposts = get_posts( "numberposts=" . $posts_to_show );
  20. foreach$myposts as $post ) { ?>
  21.   <url>
  22.       <loc><?php the_permalink(); ?></loc>
  23.       <lastmod><?php the_time('c') ?></lastmod>
  24.       <changefreq>monthly</changefreq>
  25.       <priority>0.6</priority>
  26.   </url>
  27. <?php } // end foreach ?>
  28. </urlset>

②根据环境设置url转发规则到网站根目录下的.htaccess中:

首先,apache下的规则为(补充一下,这行代码如果在你还有别的代码的情况下,一定要放在最后一行,否则会影响跳转到index.php的规则的。):

  1. RewriteEngine On
  2. RewriteBase /
  3. RewriteRule ^sitemap.xml$ xmlmap.php

然后,nginx下的规则为:

  1. rewrite ^/sitemap.xml$ /xmlmap.php;

3、wordpress建立html和xml百度网站地图插件

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注