欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

百度站点地图sitemap.xml生成代码

程序员文章站 2022-06-05 10:18:16
...
百度目前还没有开放站点地图数据提交,但可以通过,百度站长工具的开放适配提交更新数据。
  1. function sitemapxml(){
  2. $user = M('sethouse');//thinkphp 数据链接
  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");//昨天
  8. $lastweekArr = $link->query("select * from pre_sethouse where status=1 and time>$lastweek");//上周
  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. 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. ';
  29. $fp=fopen('sitemap.xml','w+');
  30. fwrite($fp,$content);
  31. fclose($fp);
  32. }
  33. function create_item($data){
  34. $item="\n";
  35. $item.="".$data['loc']."\n";
  36. $item.="".$data['lastmod']."\n";
  37. $item.="".$data['changefreq']."\n";
  38. $item.="".$data['priority']."\n";
  39. $item.="".$data['data']."\n";
  40. $item.="
  41. \n";
  42. return $item;
  43. }
复制代码