wordpress非插件實現創建html以及xml格式的站點地圖(sitemap)


wordpresss非插件建立html格式的網站地圖的方法:

1、首先下載小V這里為大家准備好了的html站點地圖的模板文件:百度網盤

2、將html站點地圖模板文件上傳至當前使用的wordpress主題的目錄下。

3、在后台新建一個內容為空標題為站點地圖,模板為站點地圖地圖的頁面

選擇模板

然后發布即可創建html格式的站點地圖,好了,說完了如何不用插件制作wordpress的html格式的網站地圖,接下來小V在教大家如何不使用插件創建wordpress的xml格式的網站地圖。

 

xml地圖的創建方法就更簡單了,新建一個名為xmlmap.php的文件,然后填入以下代碼:

<?php
require('./wp-blog-header.php');
header("Content-type: text/xml");
header('HTTP/1.1 200 OK');
$posts_to_show = 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>http://www.v7v3.com/</loc>
      <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文件傳至網站根目錄,然后根據環境寫好url轉發規則。

首先是apache下的規則:

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

將以上代碼加入到.htaccess文件即可,接下來是nginx下規則:

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

 

文章來源:v7v3.com 編輯:wordpress愛好者


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM