WordPress怎么增加网站地图

   2025-07-22 admin00100
下面由WordPress教程栏目给大家介绍WordPress增加网站地图的方法,希望对需要的朋友有所帮助!

先说一句口号:能用代码解决的,坚决不用插件!

wordpress的网站地图用一般的生成工具,生成之后都不能用,比如织梦我常用sitemapx,结果放在wordpress就出错了。

WordPress生成网站地图的插件也有很多,大家可以自行百度,这里主要是讲利用代码生成。

1.先将以下代码将保存为sitemap.php,传到网站根目录。 

<?phprequire('./wp-blog-header.php');header("Content-type:text/xml");header('HTTP/1.1200OK');$posts_to_show=1000;echo'<?xmlversion="1.0"encoding="UTF-8"?>';echo'<urlsetxmlns="http://www.sitemaps.org/schemas/sitemap/0.9"xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">'?><!--generated-on=<?phpechoget_lastpostdate('blog');?>DiyBy独立站大学(http://dulizhandaxue.com)--><url><loc><?phpechoget_home_url();?></loc><lastmod><?php$ltime=get_lastpostmodified(GMT);$ltime=gmdate('Y-m-d\TH:i:s+00:00',strtotime($ltime));echo$ltime;?></lastmod><changefreq>daily</changefreq><priority>1.0</priority></url><?php$myposts=get_posts("numberposts=".$posts_to_show);foreach($mypostsas$post){?><url><loc><?phpthe_permalink();?></loc><lastmod><?phpthe_time('c')?></lastmod><changefreq>monthly</changefreq><priority>0.6</priority></url><?php}?><?php$mypages=get_pages();if(count($mypages)>0){foreach($mypagesas$page){?><url><loc><?phpechoget_page_link($page->ID);?></loc><lastmod><?phpechostr_replace("","T",get_page($page->ID)->post_modified);?>+00:00</lastmod><changefreq>weekly</changefreq><priority>0.6</priority></url><?php}}?><?php$terms=get_terms('category','orderby=name&hide_empty=0');$count=count($terms);if($count>0){foreach($termsas$term){?><url><loc><?phpechoget_term_link($term,$term->slug);?></loc><changefreq>weekly</changefreq><priority>0.8</priority></url><?php}}?><?php$tags=get_terms("post_tag");foreach($tagsas$key=>$tag){$link=get_term_link(intval($tag->term_id),"post_tag");if(is_wp_error($link))returnfalse;$tags[$key]->link=$link;?><url><loc><?phpecho$link?></loc><changefreq>monthly</changefreq><priority>0.4</priority></url><?php}?></urlset>
 
举报收藏 0打赏 0评论 0
 
更多>同类资讯
推荐图文
推荐资讯
点击排行
网站首页  |  关于我们  |  联系方式  |  用户协议  |  隐私政策  |  版权声明  |  网站地图  |  RSS订阅
Powered By DESTOON