为了百度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 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 .= "\r\n"; //archiver输出 $archiver=$CFG['url'].'archiver/'; $data .= $archiver; $data .= "\r\n"; foreach($mods as $mid) { $indexhtm='index-htm-mid-'; $htm='.html'; $midurl=$archiver.$indexhtm.$mid.$htm; $data .= $midurl; $data .= "\r\n"; } //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 .= "\r\n"; 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 .= "\r\n";; } } } } $data .= $item; //$data = str_replace('><', ">\n<", $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 .= "\r\n"; foreach(cache_read('category-'.$mid.'.php') as $c) { $data .= $url.$c['linkurl']; $data .= "\r\n"; } $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 .= "\r\n"; } } $data .= $item; $data .= "\r\n"; //$data = str_replace('><', ">\n<", $data); file_put(DT_ROOT.'/'.$MODULE[$mid]['moduledir'].'/sitemaps.txt', $data); } } return true; ?>
然后保存为utf-8格式即可,然后进入后台更新下sitemap吧,是不是可以生成sitemap.txt文件了,觉得不错就收藏转发吧!
演示地址:http://www.sdfymj.com/sitemaps.txt