Home  >  Article  >  Backend Development  >  Baidu sitemap sitemap.xml generated code

Baidu sitemap sitemap.xml generated code

WBOY
WBOYOriginal
2016-07-25 08:49:111258browse
Baidu currently does not open sitemap data submission, but you can submit updated data through the open adaptation of Baidu Webmaster Tools.
  1. function sitemapxml(){
  2. $user = M('sethouse');//thinkphp data link
  3. $today = date("Y-m-d",time());
  4. $yesterday = mktime(0, 0, 0, date("m") , date("d")-1, date("Y"));
  5. $lastweek = strtotime("-1 week");
  6. $link = M();
  7. $yesterdayArr = $link->query("select * from pre_sethouse where status=1 and time>$yesterday");//Yesterday
  8. $lastweekArr = $link->query("select * from pre_sethouse where status=1 and time> ;$lastweek");//Last week
  9. $url = "http://www.xxx.com/House/housecontent/id/";
  10. foreach($yesterdayArr as $k=>$v){
  11. $ data_array[$k]['loc'] = $url.$v['hid'];
  12. $data_array[$k]['lastmod'] = $today;
  13. $data_array[$k]['changefreq'] = 'always';
  14. $data_array[$k]['priority'] = '0.6';
  15. $data_array[$k]['data'] = '';
  16. }
  17. $content=''.chr(13).'';
  18. $content.='
  19. < loc>http://www.xxx.com
  20. '.$today.'
  21. always
  22. 0.9
  23. '.chr(13);
  24. foreach($data_array as $data){
  25. $content.=create_item ($data);
  26. }
  27. $content.='';
  28. $fp=fopen('sitemap.xml','w+');
  29. fwrite($fp,$content);
  30. fclose( $fp);
  31. }
  32. function create_item($data){
  33. $item="n";
  34. $item.="".$data['loc']."n";
  35. $item.="".$data['lastmod']."n";
  36. $item.="".$data[' changefreq']."n";
  37. $item.="".$data['priority']."n";
  38. $item.="< data>".$data['data']."n";
  39. $item.="n";
  40. return $item;
  41. }
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn