Pigji.com
美国vps、国外主机评测!

Wordpress生成sitemap.xml网站地图提交百度!

百度搜索资源平台,不再支持索引式的sitemap地图呢。但是wordpress的网站地图插件基本是基于google的索引式的。然后感谢网友提供了一个方案,让wordpress自动生成sitemap.xml 。

首先我们在网站根目录创建一个 sitemapcn.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="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">'
?>
<!-- generated-on=<?php echo get_lastpostdate('blog'); ?> -->
  <url>
      <loc><?php echo get_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
/* 文章页面 */
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.7</priority>
  </url>
<?php } /* 文章循环结束 */ ?>
<?php
/* 单页面 */
$mypages = get_pages();
if(count($mypages) > 0) {
    foreach($mypages 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 }} /* 单页面循环结束 */ ?>
<?php
/* 博客分类 */
$terms = get_terms('category', 'orderby=name&hide_empty=0' );
$countcount = count($terms);
if($count > 0){
foreach ($terms as $term) { ?>
    <url>
      <loc><?php echo get_term_link($term, $term->slug); ?></loc>
      <changefreq>weekly</changefreq>
      <priority>0.8</priority>
  </url>
<?php }} /* 分类循环结束 */?>
<?php
 /* 标签(可选) */
$tags = get_terms("post_tag");
foreach ( $tags as $key => $tag ) {
    $link = get_term_link( intval($tag->term_id), "post_tag" );
         if ( is_wp_error( $link ) )
          return false;
          $tags[ $key ]->link = $link;
?>
 <url>
      <loc><?php echo $link ?></loc>
      <changefreq>monthly</changefreq>
      <priority>0.4</priority>
  </url>
<?php  } /* 标签循环结束 */ ?>
</urlset>

然后需要去宝塔面板给网站添加伪静态规则:

Apache:

RewriteRule ^(sitemapcn)\.xml$ $1.php

Nginx:

rewrite ^/sitemapcn.xml$ /sitemapcn.php last;

也可以直接用sitemap.xml 但是可能跟google sitemap.xml冲突。所以我才改成sitemapcn.xml

wordpress生成sitemap.xml网站地图

DMIT日本Lite评测 日本Lite系列VPS三网CMI回程 解锁奈飞_猪机博客 DMIT日本Lite评测 日本Lite系列VPS三网CMI回程 解锁奈飞 dmit日本Lite VPS评测:DMIT日本东京机房有 Premium 和 Lite二种套餐。日本Lite系列AMD EPYC 7402P的CPU,目前三网走CMI回程,较延迟低60~80ms左右体...阅读全文 Spartanhost斯巴达AMD Ryzen VPS评测,高防VPS+回程优化_猪机博客 Spartanhost斯巴达AMD Ryzen VPS评测,高防VPS+回程优化 Spartanhost西雅图机房AMD VPS评测:AMD Ryzen9 3950X/5950X),西雅图机房三网AS4837回程优化,默认10Gbps带宽,去程带ceranetwords20GB/s...阅读全文

然后访问你的域名/sitemapcn.xml 看看效果,你的wordpress网站的XML格式的网站地图sitemap就生成好了。

赞(2)
未经允许不得转载:猪机博客 » Wordpress生成sitemap.xml网站地图提交百度!

相关推荐

  • 暂无文章

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #0

    感谢分享,谢谢站长!!@天天下载

    天天下载资源网(TTzip.com)1年前 (2023-04-07)回复