15
2024
08
22:27:33

ZBLOG插件 sitemap网站地图生成器 生成的XML谷歌收录报错:您的站点地图或站点地图索引文件未能正确声明命名空间的错误




mportant;">当我们提交sitemap地图到Google网站控制台时,会出现您的站点地图或站点地图索引文件未能正确声明命名空间的错误,那是怎么回事呢。接下来我告诉大家如何修改。

<!--站点地图文件 正确示例-->
<?xml version="1.0" encoding="utf-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.aaaaaa.com</loc>
<lastmod>2022-01-23T11:03:59+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
</urlset>


我们需要找到网站主域名的sitemap.xml界面,查看是否添加了谷歌sitemap文件的命名空间的定义,添加上 就可以了。<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

成功案例演示:






您的站点地图或站点地图索引文件未能正确声明命名空间。在 Google Search Console 网站管理工具中查看到的一个提示,将blog的 XML 文件都重写了,包括站点地图文件 sitemap.xml,由于没有考虑到站点地图的标准和规范化,所以才出现了这样的情况。

站点地图 XML 文件命名空间

不得不说 Google 一直以来在各个标准上都做到了无微不至,可能在不理解的情况下会显得非常多余,因为在国内非常多的开发包括搜索引擎方面的要求或者规范上面,可以说是相当的随意,几乎谈不上有任何的规范而言,每个搜索引擎都享有自己的东西,都并不是那么愿意去遵循一些国际或者行业中的标准规范,最简单的一个体现就是今天子凡发现在站点地图 sitemap.xml 文件中,有搜索引擎支持 xml 文件,还支持 txt 文件,但是对于 XML 文件中如果没有标准的开发似乎也能够正常的被抓取,管理上面很疏松,所以似乎子凡也开始被习惯了,比较能用就行了嘛!

但是在 Google 方面,由于地图文件的 XML 命名空间没有标记出来,Google Search Console 则给出了提示,由此可见 Google 在细节方面和规范化上面的执着追求,这一点似乎没办法比拟。

子凡也就不废话了,根据子凡给出的示例代码,你应该就能够看出问题所在以及知道该如何修改处理了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!--站点地图索引文件 正确示例-->
<?xml version="1.0" encoding="utf-8" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
	<loc>https://leixue.com/xml/sitemap/sitemap-1.xml</loc>
	<lastmod>2018-12-20</lastmod>
</sitemap>
</sitemapindex>
<!-- Fanly XML SiteMap: 2018-12-21 11:46:19 -->
 
<!--站点地图文件 正确示例-->
<?xml version="1.0" encoding="utf-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
	<loc>https://leixue.com</loc>
	<lastmod>2018-12-20T14:13:59+00:00</lastmod>
	<changefreq>daily</changefreq>
	<priority>1.0</priority>
</url>
</urlset>
<!-- Fanly XML SiteMap: 2018-12-21 11:46:19 -->

以上就是目前正在使用,并且符合 Google 站点地图,站点地图的根元素已包含正确的命名空间,如果未包含或者命名空间未正确声明、存在拼写错误或网址不正确。根据的文件类型使用正确的命名空间。例如:

  • 站点地图文件:xmlns=”http://www.sitemaps.org/schemas/sitemap/0.9″

  • 视频站点地图文件:xmlns:video=”http://www.google.com/schemas/sitemap-video/1.1″

  • 站点地图索引文件:

    1
    <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

好啦,如果你也遇到同样的问题,相信你应该能够发现问题所在,并且能够直接解决问题,其实对于地图文件引入命名空间这回事情,许多 WordPress 地图插件其实都是没有问题的,甚至命名空间写得还非常详细,但是对于普通的使用,基础的标准使用其实就足够了,这样能在一定程度上获得更简洁的代码和速度,至少子凡喜欢在遵守标准规范的同时力求极致。



















附上准确的代码,直接覆盖 zb_users/plugin/mo_sitemap/include.php  ,覆盖之前建议备份源文件





<?php

#注册插件

RegisterPlugin("mo_sitemap","ActivePlugin_mo_sitemap");


function ActivePlugin_mo_sitemap() {}

function mo_sitemap_MakeSiteMapHtml(){

global $zbp;

$htmls=file_get_contents(dirname(__FILE__).'/sitemap.dat');

$htmls=str_replace('{网站名称}',$zbp->name,$htmls);

$htmls=str_replace('{host}',$zbp->host,$htmls);

$htmls=str_replace('{time}',date('Y-m-d H:i:s',time()),$htmls);

$maxnum = ($zbp->Config('mo_sitemap')->UrlNum !='')?$zbp->Config('mo_sitemap')->UrlNum:5000;

$maxpage = ($zbp->Config('mo_sitemap')->UrlPage != '')?$zbp->Config('mo_sitemap')->UrlPage:5;


//文章0.8

if($zbp->Config('mo_sitemap')->SitemapArticle == '1'){

$w=array();$o=array();$l=array();$t='';

$w[] = array('=','log_Status',0);

$w[] = array('=','log_Type',0);

$o = array('log_PostTime'=>'DESC');

for ($i=0; $i < $maxpage; $i++) { 

$l = array(($maxnum*$i),$maxnum);

$array=$zbp->GetPostList('*',$w,$o,$l);

$an = count($array);

if($an>0){

$html = $htmls;

foreach($array as $key => $v){

$t .= '<tr><td><a href="'.$v->Url.'">'.$v->Title.'</a></td></tr>'."\r\n";

}

$html=str_replace('{content}',$t,$html);

file_put_contents($zbp->path.'sitemap_article_'.($i+1).'.html',$html);

}

unset($array);

$t='';

if($an<$maxnum){break;}

}unset($i);

}

//页面0.8

if($zbp->Config('mo_sitemap')->SitemapPage == '1'){

$w=array();$o=array();$l=array();$t = '';

$w[] = array('=','log_Status',0);

$w[] = array('=','log_Type',1);

$o = array('log_PostTime'=>'DESC');

for ($i=0; $i < $maxpage; $i++) {

$l = array(($maxnum*$i),$maxnum);

$array=$zbp->GetPostList('*',$w,$o,$l);

$an = count($array);

if($an>0){

$html = $htmls;

foreach($array as $key => $v){

$t .= '<tr><td><a href="'.$v->Url.'">'.$v->Title.'</a></td></tr>'."\r\n";

}

$html=str_replace('{content}',$t,$html);

file_put_contents($zbp->path.'sitemap_page_'.($i+1).'.html',$html);

}

unset($array);

$t='';

if($an<$maxnum){break;}

}unset($i);

}

//分类0.6

if($zbp->Config('mo_sitemap')->SitemapCate == '1'){

$w=array();$o=array();$l=array();$t='';

for ($i=0; $i < $maxpage; $i++) {

$l = array(($maxnum*$i),$maxnum);

$array=$zbp->GetCategoryList('*',$w,$o,$l);

$an = count($array);

if($an>0){

$html = $htmls;

foreach($array as $key => $v){

$t .= '<tr><td><a href="'.$v->Url.'">'.$v->Name.'</a></td></tr>'."\r\n";

}

$html=str_replace('{content}',$t,$html);

file_put_contents($zbp->path.'sitemap_cate_'.($i+1).'.html',$html);

}

unset($array);

$t='';

if($an<$maxnum){break;}

}unset($i);

}

//标签0.6

if($zbp->Config('mo_sitemap')->SitemapTag == '1'){

$w=array();$o=array();$l=array();$t='';

for ($i=0; $i < $maxpage; $i++) {

$l = array(($maxnum*$i),$maxnum);

$array=$zbp->GetTagList('*',$w,$o,$l);

$an = count($array);

if($an>0){

$html = $htmls;

foreach($array as $key => $v){

$t .= '<tr><td><a href="'.$v->Url.'">'.$v->Name.'</a></td></tr>'."\r\n";

}

$html=str_replace('{content}',$t,$html);

file_put_contents($zbp->path.'sitemap_tag_'.($i+1).'.html',$html);

}

unset($array);

$t='';

if($an<$maxnum){break;}

}unset($i);

}



// $html=str_replace('{articles}',$html_Articles,$html);

// file_put_contents($zbp->path.'sitemaps.html',$html);

}

function mo_sitemap_MakeSiteMapTxt(){

global $zbp;

$maxnum = ($zbp->Config('mo_sitemap')->UrlNum !='')?$zbp->Config('mo_sitemap')->UrlNum:5000;

$maxpage = ($zbp->Config('mo_sitemap')->UrlPage != '')?$zbp->Config('mo_sitemap')->UrlPage:5;

//文章0.8

if($zbp->Config('mo_sitemap')->SitemapArticle == '1'){

$w=array();$o=array();$l=array();$t=$zbp->host."\r\n";

$w[] = array('=','log_Status',0);

$w[] = array('=','log_Type',0);

$o = array('log_PostTime'=>'DESC');

for ($i=0; $i < $maxpage; $i++) { 

$l = array(($maxnum*$i),$maxnum);

$array=$zbp->GetPostList('*',$w,$o,$l);

$an = count($array);

if($an>0){

foreach($array as $key => $v){

$t .= $v->Url."\r\n";

}

$file = fopen(($zbp->path . 'sitemap_article_'.($i+1).'.txt'),"w")or die("Unable to open file!");

fwrite($file, $t);

fclose($file);

unset($file);

}

unset($t);

if($an<$maxnum){break;}

$t = '';

}unset($i);

}

//页面0.8

if($zbp->Config('mo_sitemap')->SitemapPage == '1'){

$w=array();$o=array();$l=array();$t=$zbp->host."\r\n";

$w[] = array('=','log_Status',0);

$w[] = array('=','log_Type',1);

$o = array('log_PostTime'=>'DESC');

for ($i=0; $i < $maxpage; $i++) {

$l = array(($maxnum*$i),$maxnum);

$array=$zbp->GetPostList('*',$w,$o,$l);

$an = count($array);

if($an>0){

foreach($array as $key => $v){

$t .= $v->Url."\r\n";

}

$file = fopen(($zbp->path . 'sitemap_page_'.($i+1).'.txt'),"w")or die("Unable to open file!");

fwrite($file, $t);

fclose($file);

unset($file);

}

unset($t);

if($an<$maxnum){break;}

$t = '';

}unset($i);

}

//分类0.6

if($zbp->Config('mo_sitemap')->SitemapCate == '1'){

$w=array();$o=array();$l=array();$t=$zbp->host."\r\n";

for ($i=0; $i < $maxpage; $i++) {

$l = array(($maxnum*$i),$maxnum);

$array=$zbp->GetCategoryList('*',$w,$o,$l);

$an = count($array);

if($an>0){

foreach($array as $key => $v){

$t .= $v->Url."\r\n";

}

$file = fopen(($zbp->path . 'sitemap_cate_'.($i+1).'.txt'),"w")or die("Unable to open file!");

fwrite($file, $t);

fclose($file);

unset($file);

}

unset($t);

if($an<$maxnum){break;}

$t = '';

}unset($i);

}

//标签0.6

if($zbp->Config('mo_sitemap')->SitemapTag == '1'){

$w=array();$o=array();$l=array();$t=$zbp->host."\r\n";

for ($i=0; $i < $maxpage; $i++) {

$l = array(($maxnum*$i),$maxnum);

$array=$zbp->GetTagList('*',$w,$o,$l);

$an = count($array);

if($an>0){

foreach($array as $key => $v){

$t .= $v->Url."\r\n";

}

$file = fopen(($zbp->path . 'sitemap_tag_'.($i+1).'.txt'),"w")or die("Unable to open file!");

fwrite($file, $t);

fclose($file);

unset($file);

}

unset($t);

if($an<$maxnum){break;}

$t = '';

}unset($i);

}

}

function mo_sitemap_MakeSiteMapXml(){

global $zbp;$t='';

$t .= '<?xml version="1.0" encoding="UTF-8"?>'."\r\n";

$t .= ' <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\r\n";

$maxnum = ($zbp->Config('mo_sitemap')->UrlNum !='')?$zbp->Config('mo_sitemap')->UrlNum:5000;

$maxpage = ($zbp->Config('mo_sitemap')->UrlPage != '')?$zbp->Config('mo_sitemap')->UrlPage:5;

//文章0.8

if($zbp->Config('mo_sitemap')->SitemapArticle == '1'){

$w=array();$o=array();$l=array();

$w[] = array('=','log_Status',0);

$w[] = array('=','log_Type',0);

$o = array('log_PostTime'=>'DESC');

for ($i=0; $i < $maxpage; $i++) { 

$l = array(($maxnum*$i),$maxnum);

$array=$zbp->GetPostList('*',$w,$o,$l);

$an = count($array);

if($an>0){

$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />');

//首页

$url = $xml->addChild('url');//xml标签url

$url->addChild('loc', $zbp->host);//网站url

$url->addChild('lastmod',date('Y-m-d'));//更新时间

$url->addChild('changefreq', 'Daily');//抓取频率

$url->addChild('priority', '1.0');//抓取权重

foreach($array as $key => $v){

$url = $xml->addChild('url');

$url->addChild('loc', $v->Url);

$url->addChild('lastmod',date('Y-m-d',$v->PostTime));

$url->addChild('changefreq', $zbp->Config('mo_sitemap')->SitemapArticleFreq);

$url->addChild('priority', $zbp->Config('mo_sitemap')->SitemapArticleRank);

}

file_put_contents($zbp->path . 'sitemap_article_'.($i+1).'.xml',$xml->asXML());

$t .= ' <sitemap>'."\r\n";

$t .= ' <loc>'.$zbp->host . 'sitemap_article_'.($i+1).'.xml</loc>'."\r\n";

$t .= ' <lastmod>'.date('Y-m-d').'</lastmod>'."\r\n";

$t .= ' </sitemap>'."\r\n";

unset($xml);

}

unset($array);

if($an<$maxnum){break;}

}unset($i);

}

//页面0.8

if($zbp->Config('mo_sitemap')->SitemapPage == '1'){

$w=array();$o=array();$l=array();

$w[] = array('=','log_Status',0);

$w[] = array('=','log_Type',1);

$o = array('log_PostTime'=>'DESC');

for ($i=0; $i < $maxpage; $i++) {

$l = array(($maxnum*$i),$maxnum);

$array=$zbp->GetPostList('*',$w,$o,$l);

$an = count($array);

if($an>0){

$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />');

//首页

$url = $xml->addChild('url');//xml标签url

$url->addChild('loc', $zbp->host);//网站url

$url->addChild('lastmod',date('Y-m-d'));//更新时间

$url->addChild('changefreq', 'Daily');//抓取频率

$url->addChild('priority', '1.0');//抓取权重

foreach($array as $key => $v){

$url = $xml->addChild('url');

$url->addChild('loc', $v->Url);

$url->addChild('lastmod',date('Y-m-d',$v->PostTime));

$url->addChild('changefreq', $zbp->Config('mo_sitemap')->SitemapPageFreq);

$url->addChild('priority', $zbp->Config('mo_sitemap')->SitemapPageRank );

}

file_put_contents($zbp->path . 'sitemap_page_'.($i+1).'.xml',$xml->asXML());

$t .= ' <sitemap>'."\r\n";

$t .= ' <loc>'.$zbp->host . 'sitemap_page_'.($i+1).'.xml</loc>'."\r\n";

$t .= ' <lastmod>'.date('Y-m-d').'</lastmod>'."\r\n";

$t .= ' </sitemap>'."\r\n";

unset($xml);

}

unset($array);

if($an<$maxnum){break;}

}unset($i);

}

//分类0.6

if($zbp->Config('mo_sitemap')->SitemapCate == '1'){

$w=array();$o=array();$l=array();

for ($i=0; $i < $maxpage; $i++) {

$l = array(($maxnum*$i),$maxnum);

$array=$zbp->GetCategoryList('*',$w,$o,$l);

$an = count($array);

if($an>0){

$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />');

//首页

$url = $xml->addChild('url');//xml标签url

$url->addChild('loc', $zbp->host);//网站url

$url->addChild('lastmod',date('Y-m-d'));//更新时间

$url->addChild('changefreq', 'Daily');//抓取频率

$url->addChild('priority', '1.0');//抓取权重

foreach($array as $key => $v){

$url = $xml->addChild('url');

$url->addChild('loc', $v->Url);

$url->addChild('lastmod',date('Y-m-d'));

$url->addChild('changefreq', $zbp->Config('mo_sitemap')->SitemapCateFreq);

$url->addChild('priority', $zbp->Config('mo_sitemap')->SitemapCateRank);

}

file_put_contents($zbp->path . 'sitemap_cate_'.($i+1).'.xml',$xml->asXML());

$t .= ' <sitemap>'."\r\n";

$t .= ' <loc>'.$zbp->host . 'sitemap_cate_'.($i+1).'.xml</loc>'."\r\n";

$t .= ' <lastmod>'.date('Y-m-d').'</lastmod>'."\r\n";

$t .= ' </sitemap>'."\r\n";

unset($xml);

}

unset($array);

if($an<$maxnum){break;}

}unset($i);

}

//标签0.6

if($zbp->Config('mo_sitemap')->SitemapTag == '1'){

$w=array();$o=array();$l=array();

for ($i=0; $i < $maxpage; $i++) {

$l = array(($maxnum*$i),$maxnum);

$array=$zbp->GetTagList('*',$w,$o,$l);

$an = count($array);

if($an>0){

$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />');

//首页

$url = $xml->addChild('url');//xml标签url

$url->addChild('loc', $zbp->host);//网站url

$url->addChild('lastmod',date('Y-m-d'));//更新时间

$url->addChild('changefreq', 'Daily');//抓取频率

$url->addChild('priority', '1.0');//抓取权重

foreach($array as $key => $v){

$url = $xml->addChild('url');

$url->addChild('loc', $v->Url);

$url->addChild('lastmod',date('Y-m-d'));

$url->addChild('changefreq', $zbp->Config('mo_sitemap')->SitemapTagFreq);

$url->addChild('priority', $zbp->Config('mo_sitemap')->SitemapTagRank);

}

file_put_contents($zbp->path . 'sitemap_tag_'.($i+1).'.xml',$xml->asXML());

$t .= ' <sitemap>'."\r\n";

$t .= ' <loc>'.$zbp->host . 'sitemap_tag_'.($i+1).'.xml</loc>'."\r\n";

$t .= ' <lastmod>'.date('Y-m-d').'</lastmod>'."\r\n";

$t .= ' </sitemap>'."\r\n";

unset($xml);

}

unset($array);

if($an<$maxnum){break;}

}unset($i);

}


$t .= ' </sitemapindex>'."\r\n";


file_put_contents($zbp->path . 'sitemaps.xml',$t);

}


function InstallPlugin_mo_sitemap() {

global $zbp;

if(!$zbp->HasConfig('mo_sitemap')) {

$zbp->Config('mo_sitemap')->SitemapXml=1;

$zbp->Config('mo_sitemap')->SitemapArticle=1;

$zbp->Config('mo_sitemap')->SitemapArticleRank='0.8';

$zbp->Config('mo_sitemap')->SitemapArticleFreq='Daily';

$zbp->Config('mo_sitemap')->SitemapPage=1;

$zbp->Config('mo_sitemap')->SitemapPageRank='0.8';

$zbp->Config('mo_sitemap')->SitemapPageFreq='Daily';

$zbp->Config('mo_sitemap')->SitemapCate=1;

$zbp->Config('mo_sitemap')->SitemapCateRank='0.6';

$zbp->Config('mo_sitemap')->SitemapCateFreq='Daily';

$zbp->Config('mo_sitemap')->SitemapTag=1;

$zbp->Config('mo_sitemap')->SitemapTagRank='0.6';

$zbp->Config('mo_sitemap')->SitemapTagFreq='weekly';

$zbp->Config('mo_sitemap')->UrlNum='5000';

$zbp->Config('mo_sitemap')->UrlPage='5';

$zbp->SaveConfig('mo_sitemap');

}

}

function UninstallPlugin_mo_sitemap() {

global $zbp;

// $zbp->DelConfig('mo_sitemap');

}




推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

本文链接:https://hqyman.cn/post/7649.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:
打赏





休息一下~~


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

请先 登录 再评论,若不是会员请先 注册

您的IP地址是: