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爱好者