xml地圖的創(chuàng)建方法就更簡單了,新建一個名為xmlmap.php的文件,然后填入以下代碼:
- <?php
- include '/includes/connection.php';
- require('./wp-blog-header.php');
- header("Content-type: text/xml");
- header('HTTP/1.1 200 OK');
- $posts_to_show = 1000; // 獲取文章數(shù)量
- 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.9http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
- ?>
- <!-- generated-on=<?php echo get_lastpostdate('blog'); ?>-->
- <url>
- <lastmod><?php echo get_lastpostdate('blog'); ?></lastmod>
- <changefreq>daily</changefreq>
- <priority>1.0</priority>
- </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>
- </url>
- <?php } // end foreach ?>
- </urlset>
將xmlmap.php文件傳至網(wǎng)站根目錄,然后根據(jù)環(huán)境寫好url轉發(fā)規(guī)則。
首先是apache下的規(guī)則:
- RewriteEngine On
- RewriteBase /
- RewriteRule ^sitemap.
將以上代碼加入到.htaccess文件即可,接下來是nginx下規(guī)則:
- rewrite ^/sitemap.xml$ /xmlmap.php;
更多相關文章
版權聲明:文章圖片資源來源于網(wǎng)絡,如有侵權,請留言刪除!!!
評論