为了百度seo需要,看百度站长平台可以提交sitemap.txt地图,顺便加了这个功能,供广大爱好者学习参考。
首先找到:/module/extend/admin/template/setting.tpl.php
找到:
<td><?php echo timetodate(filemtime(DT_ROOT.'/sitemaps.xml'));?> <a href="?moduleid=<?php echo $moduleid;?>&file=sitemap&action=sitemaps" class="t">立即更新</a></td> </tr>
添加以下代码:
<tr> <td class="tl">更新txt地图</td> <td><?php echo timetodate(filemtime(DT_ROOT.'/sitemaps.txt'));?> <a href="?moduleid=<?php echo $moduleid;?>&file=sitemap&action=sitemaptxt" class="t">立即更新</a></td> </tr>
然后找到文件:/module/extend/admin/sitemap.inc.php
找到以下代码:
if($action == 'sitemaps') { tohtml('sitemaps', $module); msg('SiteMaps 更新成功', '?moduleid='.$moduleid.'&file=setting#sitemaps'); }
在下面添加:
else if($action == 'sitemaptxt'){ tohtml('sitemaptxt', $module); msg('SiteMaps 更新成功', '?moduleid='.$moduleid.'&file=setting#sitemaps'); }
最后在/module/extend/目录下新建一个:sitemaptxt.htm.php 文件
添加以下代码:
<?php /* 作者:68喜科技 网站:www.sdfymj.com 时间:2020/2/9 功能:dt7.0站点地图(sitemap.txt)输出 */ defined('IN_DESTOON') or exit('Access Denied'); if(!$MOD['sitemaps']) { file_del(DT_ROOT.'/sitemaps.txt'); return false; } $moodule_count= count($mods);//模块个数 $mods = explode(',', $MOD['sitemaps_module']); $nums = intval($MOD['sitemaps_items']*1.2);//尽量凑成5万条 $data .= DT_PATH; $data .= " "; //archiver输出 $archiver=$CFG['url'].'archiver/'; $data .= $archiver; $data .= " "; foreach($mods as $mid) { $indexhtm='index-htm-mid-'; $htm='.html'; $midurl=$archiver.$indexhtm.$mid.$htm; $data .= $midurl; $data .= " "; } //archiver输出end $item = ''; foreach($mods as $mid) { if(isset($MODULE[$mid]) && !$MODULE[$mid]['islink'] && !$MODULE[$mid]['domain']) { if($mid == 4 && $CFG['com_domain']) continue; $url = $MODULE[$mid]['linkurl']; $data .= $url; $data .= " "; if($nums) { $fields = $mid == 4 ? 'linkurl' : 'linkurl,edittime'; $order = $mid == 4 ? 'userid' : 'addtime'; $condition = $mid == 4 ? "catids<>''" : "status>2"; $result = $db->query("SELECT $fields FROM ".get_table($mid)." WHERE $condition ORDER BY $order DESC LIMIT $nums"); while($r = $db->fetch_array($result)) { $item .= xml_linkurl($r['linkurl'], $url); $item .= " ";; } } } } $data .= $item; //$data = str_replace('><', "> <", $data); file_put(DT_ROOT.'/sitemaps.txt', $data); foreach($mods as $mid) { if(isset($MODULE[$mid]) && !$MODULE[$mid]['islink'] && $MODULE[$mid]['domain']) { if($mid == 4 && $CFG['com_domain']) continue; $url = $MODULE[$mid]['linkurl']; $data .= $url; $data .= " "; foreach(cache_read('category-'.$mid.'.php') as $c) { $data .= $url.$c['linkurl']; $data .= " "; } $item = ''; $nums = intval($MOD['sitemaps_items']); if($nums) { $fields = $mid == 4 ? 'linkurl' : 'linkurl,edittime'; $order = $mid == 4 ? 'userid' : 'addtime'; $condition = $mid == 4 ? "catids<>''" : "status>2"; $result = $db->query("SELECT $fields FROM ".get_table($mid)." WHERE $condition ORDER BY $order DESC LIMIT $nums"); while($r = $db->fetch_array($result)) { $item .=xml_linkurl($r['linkurl'], $url); $item .= " "; } } $data .= $item; $data .= " "; //$data = str_replace('><', "> <", $data); file_put(DT_ROOT.'/'.$MODULE[$mid]['moduledir'].'/sitemaps.txt', $data); } } return true; ?>
然后保存为utf-8格式即可,然后进入后台更新下sitemap吧,是不是可以生成sitemap.txt文件了,觉得不错就收藏转发吧!