对于做SEO网站优化的朋友们来说,SiteMap.xml网站地图的重要性无可比拟,对于网站地图一般分两种,html和xml。在之前的教程中,Ourboke联盟提到了WordPress如何用代码制作SiteMap.html网站地图的操作方法,今天来讲下xml的制作。

WordPress纯代码制作SiteMap.xml网站地图
1.在网站根目录新建一个Sitemap.php文件
2.文件中填入以下代码:
<?php require('./wp-blog-header.php'); header("Content-type: text/xml"); header('HTTP/1.1 200 OK'); 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 https://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'; ?> <!-- generated-on=<?php echo get_lastpostdate('blog'); ?>--> <url> <loc><?php echo get_home_url(); ?></loc> <lastmod><?php echo gmdate('Y-m-d\TH:i:s+00:00', strtotime(get_lastpostmodified('GMT'))); ?></lastmod> <changefreq>daily</changefreq> <priority>1.0</priority> </url> <?php // 文章 $posts = get_posts('numberposts=-1&orderby=post_date&order=DESC'); foreach($posts as $post) : ?> <url> <loc><?php echo get_permalink($post->ID); ?></loc> <lastmod><?php echo str_replace(" ", "T", get_post($post->ID)->post_modified); ?>+00:00</lastmod> <changefreq>monthly</changefreq> <priority>0.6</priority> </url> <?php endforeach; // 页面 $pages = get_pages('numberposts=-1&orderby=post_date&order=DESC'); foreach($pages as $page) : ?> <url> <loc><?php echo get_page_link($page->ID); ?></loc> <lastmod><?php echo str_replace(" ", "T", get_page($page->ID)->post_modified); ?>+00:00</lastmod> <changefreq>weekly</changefreq> <priority>0.6</priority> </url> <?php endforeach; // 分类 $categorys = get_terms('category', 'orderby=name&hide_empty=0'); foreach ($categorys as $category) : ?> <url> <loc><?php echo get_term_link($category, $category->slug); ?></loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url> <?php endforeach; // 标签 $tags = get_terms('post_tag', 'orderby=name&hide_empty=0'); foreach ($tags as $tag) : ?> <url> <loc><?php echo get_term_link($tag, $tag->slug); ?></loc> <changefreq>monthly</changefreq> <priority>0.4</priority> </url> <?php endforeach; ?> </urlset>
伪静态:
rewrite ^/Sitemap.xml$ /
Ourboke联盟认为,做xml网站地图还是很有必要的,它是给搜索引擎(百度、360、谷歌)的蜘蛛爬取使用的,这样做方便搜索引擎蜘蛛抓取我们的网站内容,促进网站内容的收录,最终达到提升关键词排名的作用。
2020年6月10日 下午5:00 1F
还是柳城做的Baidu Sitemap Generator插件好用,后台插件搜索一下就能找到
生成sitemap.xml后,还要去百度资源后台,把旧的sitemap.xml删除,再重新提交一下新的sitemap.xml
这样,只要经常更新,一段时间正常更新后,再用sitemap.xml提交,几分钟就能收录了
2020年6月10日 下午5:06 B1
@ 千里之外 你更新下最新begin主题还更好,主题自带sitemap.xm地图更为方便,另外我更新的这种代码的也不错,还有一种是网站生成的也不错,只要把文件放在网站根目录就好了,也很快加速收录。可能是我之前用的插件都会影响速度,所以能不用插件我都尽可能不用。
2020年6月10日 下午5:08 B2
@ Ourboke 不更新了,我修改了很多很多的内容,也加了很多代码进去,换了,根本没办法再改回来,只好一直保留去年的版本。