destoon7.0中加入站点地图(sitemap.txt)功能输出

为了百度seo需要,看百度站长平台可以提交sitemap.txt地图,顺便加了这个功能,供广大爱好者学习参考。

   首先找到:/module/extend/admin/template/setting.tpl.php

   找到:

 

 
 
  1. <td><?php echo timetodate(filemtime(DT_ROOT.'/sitemaps.xml'));?> <a href="?moduleid=<?php echo $moduleid;?>&file=sitemap&action=sitemaps" class="t">立即更新</a></td>
  2. </tr>

 

在下面添加以下代码:

 

 
 
  1. <tr>
  2. <td class="tl">更新txt地图</td>
  3. <td><?php echo timetodate(filemtime(DT_ROOT.'/sitemaps.txt'));?> <a href="?moduleid=<?php echo $moduleid;?>&file=sitemap&action=sitemaptxt" class="t">立即更新</a></td>
  4. </tr>

 

 

 

然后找到文件:/module/extend/admin/sitemap.inc.php

   找到以下代码:

 

 
 
  1. if($action == 'sitemaps') {
  2. tohtml('sitemaps', $module);
  3. msg('SiteMaps 更新成功', '?moduleid='.$moduleid.'&file=setting#sitemaps');
  4. }

 

在下面添加:

 

 
 
  1. else if($action == 'sitemaptxt'){
  2. tohtml('sitemaptxt', $module);
  3. msg('SiteMaps 更新成功', '?moduleid='.$moduleid.'&file=setting#sitemaps');
  4. }

 

 

最后在/module/extend/目录下新建一个:sitemaptxt.htm.php 文件

  添加以下代码:

 
 
  1. <?php
  2.  
  3. defined('IN_DESTOON') or exit('Access Denied');
  4. if(!$MOD['sitemaps']) {
  5. file_del(DT_ROOT.'/sitemaps.txt');
  6. return false;
  7. }
  8. $moodule_count= count($mods);//模块个数
  9. $mods = explode(',', $MOD['sitemaps_module']);
  10. $nums = intval($MOD['sitemaps_items']*1.2);//尽量凑成5万条
  11. $data .= DT_PATH;
  12. $data .= "\r\n";
  13. //archiver输出
  14. $archiver=$CFG['url'].'archiver/';
  15. $data .= $archiver;
  16. $data .= "\r\n";
  17. foreach($mods as $mid) {
  18. $indexhtm='index-htm-mid-';
  19. $htm='.html';
  20. $midurl=$archiver.$indexhtm.$mid.$htm;
  21. $data .= $midurl;
  22. $data .= "\r\n";
  23. }
  24. //archiver输出end
  25. $item = '';
  26. foreach($mods as $mid) {
  27. if(isset($MODULE[$mid]) && !$MODULE[$mid]['islink'] && !$MODULE[$mid]['domain']) {
  28. if($mid == 4 && $CFG['com_domain']) continue;
  29. $url = $MODULE[$mid]['linkurl'];
  30. $data .= $url;
  31. $data .= "\r\n";
  32. if($nums) {
  33. $fields = $mid == 4 ? 'linkurl' : 'linkurl,edittime';
  34. $order = $mid == 4 ? 'userid' : 'addtime';
  35. $condition = $mid == 4 ? "catids<>''" : "status>2";
  36. $result = $db->query("SELECt $fields FROM ".get_table($mid)." WHERe $condition ORDER BY $order DESC LIMIT $nums");
  37. while($r = $db->fetch_array($result)) {
  38. $item .= xml_linkurl($r['linkurl'], $url);
  39. $item .= "\r\n";;
  40. }
  41. }
  42. }
  43. }
  44. $data .= $item;
  45. //$data = str_replace('><', ">\n<", $data);
  46. file_put(DT_ROOT.'/sitemaps.txt', $data);
  47. foreach($mods as $mid) {
  48. if(isset($MODULE[$mid]) && !$MODULE[$mid]['islink'] && $MODULE[$mid]['domain']) {
  49. if($mid == 4 && $CFG['com_domain']) continue;
  50. $url = $MODULE[$mid]['linkurl'];
  51. $data .= $url;
  52. $data .= "\r\n";
  53. foreach(cache_read('category-'.$mid.'.php') as $c) {
  54. $data .= $url.$c['linkurl'];
  55. $data .= "\r\n";
  56. }
  57. $item = '';
  58. $nums = intval($MOD['sitemaps_items']);
  59. if($nums) {
  60. $fields = $mid == 4 ? 'linkurl' : 'linkurl,edittime';
  61. $order = $mid == 4 ? 'userid' : 'addtime';
  62. $condition = $mid == 4 ? "catids<>''" : "status>2";
  63. $result = $db->query("SELECt $fields FROM ".get_table($mid)." WHERe $condition ORDER BY $order DESC LIMIT $nums");
  64. while($r = $db->fetch_array($result)) {
  65. $item .=xml_linkurl($r['linkurl'], $url);
  66. $item .= "\r\n";
  67. }
  68. }
  69. $data .= $item;
  70. $data .= "\r\n";
  71. //$data = str_replace('><', ">\n<", $data);
  72. file_put(DT_ROOT.'/'.$MODULE[$mid]['moduledir'].'/sitemaps.txt', $data);
  73. }
  74. }
  75. return true;
  76. ?>

 

 

然后保存为utf-8格式即可,然后进入后台更新下sitemap吧,是不是可以生成sitemap.txt文件了,觉得不错就收藏转发吧!