




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
本文格式為Word版,下載可任意編輯——php自動生成sitemap地圖代碼php自動生成sitemap地圖代碼
如何生成sitemap地圖呢?本文共享一例php代碼,用于自動動態(tài)生成最新的sitemap地圖文件,并通知google網(wǎng)站地圖的'更新,感興趣的摯友參考下吧。
本節(jié)內(nèi)容:
php自動生成sitemap地圖
例子,sitemap.inc.php:主要生成sitemap的類。
代碼:
復(fù)制代碼代碼例如:
?php
//sitemapgeneratorclass
classSitemap
//constructorreceivesthelistofURLstoincludeinthesitemap
functionSitemap$items=array
$this-_items=$items;
//addanewsitemapitem
functionaddItem$url,
$lastmod=',
$changefreq=',
$priority=',
$additional_fields=array
$this-_items[]=array_mergearrayloc=$url,
lastmod=$lastmod,
changefreq=$changefreq,
priority=$priority,
$additional_fields;
//getGooglesitemap
functiongetGoogle
ob_start;
headerContent-type:text/xml;
echo?xmlversion='1.0encoding='UTF-8?;
echourlsetxmlns='http://./schemas/sitemap/0.9
xmlns:xsi='http://./2022/XMLSchema-instance'
xsi:schemaLocation='http://./schemas/sitemap/0.9
http://./schemas/sitemap/0.9/sitemap.xsd';
foreach$this-_itemsas$i
echourl;
foreach$ias$index=$_i
if!$_icontinue;
echo"$index'.$this-_escapeXML$_i."/$index';
echo/url;
echo/urlset;
returnob_get_clean;
//escapestringcharactersforinclusioninXMLstructure
function_escapeXML$str
$translation=get_html_translation_tableHTML_ENTITIES,ENT_QUOTES;
foreach$translationas$key=$value
$translation[$key]=#.ord$key.;;
$translation[chr38]=;
returnpreg_replace"/?![A-Za-z]0,4\w2,3;|#[0-9]2,3;/','#38;',
strtr$str,$translation;
?
sitemap.php:調(diào)用sitemap.inc.php,概括實現(xiàn)sitemap。
復(fù)制代碼代碼例如:
?php
//redirectrequeststodynamictotheirkeywordrichversions
require_once/sitemap.inc.php;
defineSITE_DOMAIN,http://.;
//createtheSitemapobject
$s=newSitemap;
//addsitemapitems
$s-addItemSITE_DOMAIN;
$s-addItemSITE_DOMAIN.'/aboutus.html';
$s-addItemSITE_DOMAIN.'/whatnew.php';
//連接數(shù)據(jù)庫,生成URL并通過條用$s-addItem參與到sitemap中。
//outputsitemap
ifisset$_GET[target]
//generateGooglesitemap
if$target=$_GET[target]==google
echo$s-getGoogle;
?
說明:
.htaccess文件,重定向sitemap.xml文件到sitemap.php。
RewriteEngineon
RewriteRule^sitemap.xml$sitemap.php?target=google[L]
ping_google函數(shù),在網(wǎng)站內(nèi)容更新的地方調(diào)用此函數(shù),用于自動通知Google網(wǎng)站地圖更新。
代碼:
復(fù)制代碼代碼例如:
?php
functionping_google
$sitemapUrl=http://./sitemap.xml;
$pingUrl="http://./webmasters/sitemaps/ping?sitemap='.urlencode$sitemapUrl;
$ch=curl_init;
curl_setopt$ch,CURLOPT_URL,$pingUrl;
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 客戶溝通與反饋記錄
- 小王子遇見世界的觀后感
- 高中化學(xué)實驗設(shè)計與探究:化學(xué)反應(yīng)原理教案
- 《初高中英語語法比較與辨析教案》
- 不動產(chǎn)交易買賣協(xié)議書
- 中學(xué)生歷史事件故事讀后感
- 美容師儀器知識培訓(xùn)課件
- 血液++課件-2024-2025學(xué)年北師大版生物七年級下冊
- 紅色故事鐵道游擊隊的愛國主義教育解讀
- 教育資源整合及教育信息化建設(shè)方案
- 脊柱內(nèi)鏡應(yīng)用與進展
- 鹿茸的現(xiàn)代藥理研究報告
- 化工行業(yè)儀表典型事故分析報告
- 2024年初級會計職稱《初級會計實務(wù)》真題匯編及答案
- 醫(yī)用耗材配送服務(wù)方案
- 中職統(tǒng)編《金屬材料與熱處理》系列課件 第3章 鐵碳合金(動畫) 云天系列課件
- 人教版七年級下冊地理全冊復(fù)習(xí)知識點匯總課件
- 外墻瓷磚隱患排查施工方案
- 21 自然界和社會
- 反腐倡廉廉潔行醫(yī)
- 國家公務(wù)員考試準考證模板
評論
0/150
提交評論