|
建立一个HTML的网站地图(sitemap)对于SEO和用户体验都有一定的优化,而单纯的建立一个xml的网站地图则是有利于SEO优化,之前小V曾经发布过一个wordpress的xml sitemap的插件:google sitemap generator,那么今天小V就来介绍下如何使用非插件的方法建立HTML以及XML格式的网站地图。 wordpresss非插件建立html格式的网站地图的方法: 1、首先下载小V这里为大家准备好了的html站点地图的模板文件:百度网盘 2、将html站点地图模板文件上传至当前使用的wordpress主题的目录下。 3、在后台新建一个内容为空标题为站点地图,模板为站点地图地图的页面,操作图如下: 选择模板 然后发布即可创建html格式的站点地图,好了,说完了如何不用插件制作wordpress的html格式的网站地图,接下来小V在教大家如何不使用插件创建wordpress的xml格式的网站地图。 xml地图的创建方法就更简单了,新建一个名为xmlmap.php的文件,然后填入以下代码: <?phprequire('./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><?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> 将xmlmap.php文件传至网站根目录,然后根据环境写好url转发规则。 首先是apache下的规则: RewriteEngine OnRewriteBase /RewriteRule ^sitemap.xml$ xmlmap.php 将以上代码加入到.htaccess文件即可,接下来是nginx下规则: rewrite ^/sitemap.xml$ /xmlmap.php; 至于微软的iis,小V没用过,规则怎么写?自己慢慢琢磨吧。 |
|