How to generate Baidu site map
This article mainly introduces "how to generate Baidu site map". In daily operation, I believe many people have doubts about how to generate Baidu site map. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about how to generate Baidu site map! Next, please follow the editor to study!
The copy code is as follows:
Function sitemapxml () {
$user = M ('sethouse'); / / thinkphp data link
$today = date ("Y-m-d", time ())
$yesterday = mktime (0,0,0, date ("m"), date ("d")-1, date ("Y"))
$lastweek = strtotime ("- 1 week")
$link = M ()
YesterdayArr = $link- > query ("select * from pre_sethouse where status=1 and time > $yesterday"); / / yesterday
$lastweekArr = $link- > query ("select * from pre_sethouse where status=1 and time > $lastweek"); / / last week
$url = "http://www.xxx.com/House/housecontent/id/";
Foreach ($yesterdayArr as $k = > $v) {
$data_array [$k] ['loc'] = $url.$v [' hid']
$data_array [$k] ['lastmod'] = $today
$data_array [$k] ['changefreq'] =' always'
$data_array [$k] ['priority'] =' 0.6'
$data_array [$k] ['data'] =''
}
$content=''.chr (13).
$content.='
Http://www.xxx.com
'. $today.'
Always
0.9
'.chr (13)
Foreach ($data_array as $data) {
$content.=create_item ($data)
}
$content.=''
$fp=fopen ('sitemap.xml','w+')
Fwrite ($fp,$content)
Fclose ($fp)
}
Function create_item ($data) {
$item= "\ n"
$item.= ". $data ['loc']."\ n "
$item.= ". $data ['lastmod']."\ n "
$item.= ". $data ['changefreq']."\ n "
$item.= ". $data ['priority']."\ n "
$item.= ". $data ['data']."\ n "
$item.= "\ n"
Return $item
}
At this point, the study on "how to generate Baidu site map" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!