wordpress代码实现网站地图sitemap的html和xml的方法
2017-09-23 00:13
846 查看
今天介绍的就是不使用插件完成wordpress代码实现网站地图sitemap的html和xml的方法首先我先提供下sitemap.php的文件吧: 将文件下载下来,上传到当前文件夹的根目录,然后新建页面,选择站点地图模板即可!这样一个html的站点地图就OK了。在空间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;
<?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;
相关文章推荐
- 织梦dedecms中html和xml格式的网站地图sitemap制作方法
- wordpress非插件实现创建html以及xml格式的站点地图(sitemap)
- 配置实现-自创html生成模板搭配xml获取数据无需写代码实现静态网站
- 如何制作网站地图(sitemap.html和sitemap.xml)?
- html网站地图与xml网站地图Google Sitemap生成器
- 织梦dedecms中html和xml格式的网站地图sitemap制作方法
- WordPress代码实现相关文章的几种方法(一)
- Thinkphp二级网站地图XML生成的方法[图解]
- 向各大搜索引擎提交(网站地图)SiteMap的方法
- C#.NET示例读写xml所有节点的代码实现方法和读取xml节点的数据总结
- WordPress代码实现相关文章的几种方法(二)
- CodeIgniter生成网站sitemap地图的方法
- 在winfrom下利用c#代码,实现kindEditor的JavaScript方法:editor.html(),实现上报窗体的自动提交。
- 网站安全性:C#防SQL注入代码的实现方法
- WordPress代码实现相关文章的几种方法(二)
- C#.NET示例读写xml所有节点的代码实现方法和读取xml节点的数据总结
- dedecms网站地图xml制作方法 seo一日一贴
- 快速制作网站地图文件sitemap的方法
- 黄聪:wordpress向mysql字段中保存html代码(使用add_option()方法),然后无法显示出问题