Baidu has not yet opened the site map data submission, but you can submit the updated data through the open adaptation of the Baidu webmaster tool. for details, refer to use it.
The 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 </loc>
'. $ 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;
}