当前位置:Gxlcms > PHP教程 > 百度站点地图sitemap.xml生成代码

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

时间:2021-07-01 10:21:17 帮助过:92人阅读

百度目前还没有开放站点地图数据提交,但可以通过,百度站长工具的开放适配提交更新数据。
  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. $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']."\n";
  39. $item.="\n";
  40. return $item;
  41. }

人气教程排行