首页  >  文章  >  后端开发  >  百度站点地图sitemap.xml生成代码

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

WBOY
WBOY原创
2016-07-25 08:49:111258浏览
百度目前还没有开放站点地图数据提交,但可以通过,百度站长工具的开放适配提交更新数据。
  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. }
复制代码


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn