今天就來講講關(guān)于制作xml百度結(jié)構(gòu)化地圖的問題,小編我在制作一個(gè)百度pc端和移動(dòng)端的結(jié)構(gòu)化轉(zhuǎn)換xml文件提交給搜索引擎
百度官方給的代碼示例是這樣的:
<?xml version="1.0" encoding="UTF-8"?> <urlset> <!-- urlset用來標(biāo)記整個(gè)文檔的開頭 --> <url> <!-- url標(biāo)記每條信息的開始和結(jié)束 --> <loc>http://m.dgkbdq.com/</loc> <!-- 該條數(shù)據(jù)的存放地址 --> <lastmod>2010-11-20</lastmod> <!-- 指該條數(shù)據(jù)的最新一次更新時(shí)間 --> <changefreq>always</changefreq> <!-- 指該條數(shù)據(jù)的更新頻率 --> <priority>1.0</priority> <!-- 用來指定此鏈接相對于其他鏈接的優(yōu)先權(quán)比值,此值定于0.0-1.0之間 --> <data> <display> <html5_url>http://html5.xjyili.cn/</html5_url> <!-- 可選,表示該P(yáng)C頁對應(yīng)的html5版式的手機(jī)頁的url地址,需要符合url規(guī)范 --> <wml_url>http://wml.xjyili.cn/</wml_url> <!-- 可選,表示該P(yáng)C頁對應(yīng)的wml版式的手機(jī)頁的url地址,需要符合url規(guī)范 --> <xhtml_url>http://3g.xjyili.cn/</xhtml_url> <!-- 可選,表示該P(yáng)C頁對應(yīng)的xhtml版式的手機(jī)頁的url地址,需要符合url規(guī)范 --> </display> </data> </url> </urlset>因?yàn)樾【幬沂怯玫膁iscuz程序搭建的網(wǎng)站所以就通過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='網(wǎng)站標(biāo)題'; $metakeywords='關(guān)鍵詞'; $metadescription='網(wǎng)站描述'; //include template('common/header');調(diào)用系統(tǒng)頭部 header("Content-type: text/xml");//定義頁面為xml文件 echo '<?xml version="1.0" encoding="gb2312"?> <urlset> <!-- urlset用來標(biāo)記整個(gè)文檔的開頭 --> '; $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標(biāo)記每條信息的開始和結(jié)束 -->'; echo '<loc>http://www.0999m.com/forum.php?mod=viewthread&tid='.$threadfid['tid'].'</loc> <!-- 該條數(shù)據(jù)的存放地址 -->'; echo '<lastmod>2010-11-20</lastmod> <!-- 指該條數(shù)據(jù)的最新一次更新時(shí)間 -->'; echo '<changefreq>always</changefreq> <!-- 指該條數(shù)據(jù)的更新頻率 -->'; echo '<priority>1.0</priority> <!-- 用來指定此鏈接相對于其他鏈接的優(yōu)先權(quán)比值,此值定于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> <!-- 可選,表示該P(yáng)C頁對應(yīng)的html5版式的手機(jī)頁的url地址,需要符合url規(guī)范 -->'; echo '<xhtml_url>http://www.0999m.com/forum.php?mod=viewthread&tid='.$threadfid['tid'].'&mobile=1</xhtml_url> <!-- 可選,表示該P(yáng)C頁對應(yīng)的wml版式的手機(jī)頁的url地址,需要符合url規(guī)范 -->'; 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'); ?>現(xiàn)在就遇到問題來了,火狐瀏覽器報(bào)錯(cuò),世界之窗也報(bào)錯(cuò)咋回事呢?
首先小編英語不是很懂就翻譯了一下世界之窗的代碼得到以下解釋:
提示第81列第5行報(bào)錯(cuò),那我就找找看,打開網(wǎng)頁源代碼查找;
看來問題出在URL鏈接上面了,我們只寫一個(gè)域名看看;
完全正常啊,說明問題就是出在域名后面的URL中,我去參考一下別人xml的寫法:
瞬間明白了,因?yàn)槭?amp;符號(hào)xml格式報(bào)錯(cuò),大神都是用&代碼來代替,把這個(gè)換掉之后xml瞬間正常
新疆SEO點(diǎn)評:百度結(jié)構(gòu)化地圖對你站點(diǎn)文章收錄是非常關(guān)鍵的這個(gè)功能告訴百度你的站點(diǎn)有新的好的內(nèi)容;