今天就来讲讲关于制作xml百度结构化地图的问题,小编我在制作一个百度pc端和移动端的结构化转换xml文件提交给搜索引擎
百度官方给的代码示例是这样的:
<?xml version="1.0" encoding="UTF-8"?> <urlset> <!-- urlset用来标记整个文档的开头 --> <url> <!-- url标记每条信息的开始和结束 --> <loc>http://www.xjyili.cn/</loc> <!-- 该条数据的存放地址 --> <lastmod>2010-11-20</lastmod> <!-- 指该条数据的最新一次更新时间 --> <changefreq>always</changefreq> <!-- 指该条数据的更新频率 --> <priority>1.0</priority> <!-- 用来指定此链接相对于其他链接的优先权比值,此值定于0.0-1.0之间 --> <data> <display> <html5_url>http://html5.xjyili.cn/</html5_url> <!-- 可选,表示该PC页对应的html5版式的手机页的url地址,需要符合url规范 --> <wml_url>http://wml.xjyili.cn/</wml_url> <!-- 可选,表示该PC页对应的wml版式的手机页的url地址,需要符合url规范 --> <xhtml_url>http://3g.xjyili.cn/</xhtml_url> <!-- 可选,表示该PC页对应的xhtml版式的手机页的url地址,需要符合url规范 --> </display> </data> </url> </urlset>因为小编我是用的discuz程序搭建的网站所以就通过php来书写百度xml文件 以下是小编的php代码:
<?php /** www.0999m.com * */ define('APPTYPEID', 168); define('CURSCRIPT', 'comiis'); define('CURMODULE', 'contact'); require './source/class/class_core.php'; $discuz = & discuz_core::instance(); $discuz->cachelist = $cachelist; $discuz->init(); $navtitle='网站标题'; $metakeywords='关键词'; $metadescription='网站描述'; //include template('common/header');调用系统头部 header("Content-type: text/xml");//定义页面为xml文件 echo '<?xml version="1.0" encoding="gb2312"?> <urlset> <!-- urlset用来标记整个文档的开头 --> '; $querys = DB::query("SELECT a.tid,a.subject,a.fid,b.name FROM ".DB::table('forum_thread')." as a inner join ".DB::table('forum_forum')." as b on a.fid=b.fid where a.displayorder=0 ORDER BY a.tid DESC LIMIT 0,160"); $i=1; while($threadfid = DB::fetch($querys)){ echo '<url> <!-- url标记每条信息的开始和结束 -->'; echo '<loc>http://www.0999m.com/forum.php?mod=viewthread&tid='.$threadfid['tid'].'</loc> <!-- 该条数据的存放地址 -->'; echo '<lastmod>2010-11-20</lastmod> <!-- 指该条数据的最新一次更新时间 -->'; echo '<changefreq>always</changefreq> <!-- 指该条数据的更新频率 -->'; echo '<priority>1.0</priority> <!-- 用来指定此链接相对于其他链接的优先权比值,此值定于0.0-1.0之间 -->'; echo '<data> <display>'; echo '<html5_url>http://www.0999m.com/forum.php?mod=viewthread&tid='.$threadfid['tid'].'&mobile=2</html5_url> <!-- 可选,表示该PC页对应的html5版式的手机页的url地址,需要符合url规范 -->'; echo '<xhtml_url>http://www.0999m.com/forum.php?mod=viewthread&tid='.$threadfid['tid'].'&mobile=1</xhtml_url> <!-- 可选,表示该PC页对应的wml版式的手机页的url地址,需要符合url规范 -->'; echo '</display> </data></url>'; //echo '<li>'.$i.'、<em>[<a href="forum.php?mod=forumdisplay&fid='.$threadfid['fid'].'">'.$threadfid['name'].'</a>]</em> <a href="forum.php?mod=viewthread&tid='.$threadfid['tid'].'" target="_blank" title="'.$threadfid['subject'].'">'.$threadfid['subject'].'</a></li>'; $i++; } echo '</urlset>'; //include template('common/footer'); ?>现在就遇到问题来了,火狐浏览器报错,世界之窗也报错咋回事呢?
首先小编英语不是很懂就翻译了一下世界之窗的代码得到以下解释:
完全正常啊,说明问题就是出在域名后面的URL中,我去参考一下别人xml的写法:
瞬间明白了,因为是&符号xml格式报错,大神都是用&代码来代替,把这个换掉之后xml瞬间正常
新疆SEO点评:百度结构化地图对你站点文章收录是非常关键的这个功能告诉百度你的站点有新的好的内容;
发表评论 取消回复