起首,我照样认可了吧,教程是从奶嘴那弄来的,为的也是轻易本身,顺带轻易下阅读用户们!本日引见的就是不运用插件完成wordpress代码完成网站舆图sitemap的html和xml的要领,本站之前一向用着柳城的百度舆图插件,本日心血来潮,想着照样直接代码吧,罕用插件的好!
下面我就直接说教程吧,固然如今入手下手你就可以卸掉了wordpress百度舆图的插件了!
起首我先供应下sitemap.php的文件吧:传送门 将文件下载下来,上传到当前wordpress主题文件夹的根目录,然后新建页面,挑选站点舆图模板即可!如许一个html的站点舆图就OK了。
然后我说下xml站点舆图的完成要领吧
在空间wordpress的根目录下建立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.2zzt.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>
上传到根目录后,就是设置url转发划定规矩了,目标是让http://www.2zzt.com/sitemap.xml可以被接见,固然这个sitemap.xml内容就是xmlmap.php的
依据差别的服务器环境来设置url转发划定规矩!
起首是apache下的划定规矩:
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap.xml$ xmlmap.php
将以上代码加入到.htaccess文件即可,接下来是nginx下划定规矩:
rewrite ^/sitemap.xml$ /xmlmap.php;

评论列表