很多使用 BAE 百度雲空間搭建 WordPress 博客的朋友都應該知道 BAE 是禁止本地本地 I/O(I/O 也就是本地讀寫),這樣給搭建網站帶來了很多的不便,比如説在 BAE 環境上的 WordPress 站點無法藉助插件來直接生成 sitemap 站點地圖了,那麼小編今天就來介紹如何在 BAE 環境下生成 sitemap 。

方法一:使用站點地圖生成器生成網站地圖並上傳到 BAE 環境中

在線網站地圖生成器:http://www.xml-sitemaps.com/

方法二:使用 php 動態的來讀取 WordPress 數據庫內容並列出鏈接。

首先在網站根目錄下新建一個 v7v3.sitemap.php 並加入以下代碼:

<?phpinclude 'includes/connection.php';require('./wp-blog-header.php');header("Content-type: text/xml");$posts_to_show = 1000; // 獲取文章數量echo '<?xml version="1.0" encoding="UTF-8"?>';echo '<?xml-stylesheet type="text/xsl" href="/sitemap.xsl"?>'; // XSL 地址echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';?><!-- generated-on=<?php echo get_lastpostdate('blog'); ?>--><url><loc>http://www.weixiaoduo.com/</loc>  // 此處將域名改成你的站點根目錄<lastmod><?php echo get_lastpostdate('blog'); ?></lastmod><changefreq>daily</changefreq><priority>1.0</priority></url><?phpheader("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></url><?php } // end foreach ?></urlset>

然後下載一個 Google Sitemap Generator 插件並將其中的 sitemap.xsl 取出來傳到站點根目錄,接着我們登錄 BAE 的應用管理界面高級選項中來配置 sitemap 網站地圖文件的鏈接。

添加如上圖的規則,記住,順序不能打亂,不然會造成 siemap 無法訪問。