dt7.0中在sitemap.txt地图中新增热门搜索关键词记录

   上次新增了sitemap.txt功能,这次加了一个把网站热门搜索记录全部输出到txt地图上,更有利于蜘蛛的抓取,希望对大家有帮助!

   没做过之前的功能,可以参考:https://www.cnblogs.com/68xi/p/12288221.html

   做过的话,直接在之前那里覆盖: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']);//尽量凑成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

//关键词搜索记录调取
foreach($mods as $mid) {
  $starid = 1;   //初始ID 开
  $module= $mid;//模块推送,21资讯,5供应,22招商,13品牌,9招聘,10知道,12图片,14视频,15下载,18论坛
  $domain=$CFG['url'];//这个是获取配置文件的域名,默认格式是:http://www.sdfymj.com/
if($module==21){
	$dir='news/';
}elseif($module==5){
    $dir='sell/';
}elseif($module==22){
    $dir='invest/';
}elseif($module==15){
    $dir='down/';
}elseif($module==18){
    $dir='club/';
}elseif($module==12){
    $dir='photo/';
}elseif($module==14){
    $dir='video/';
}//如果目录重新改过可以在这添加和修改

		if($nums) {
			$result = $db->query("SELECT letter FROM {$DT_PRE}keyword WHERE  itemid> $starid  AND  MODULEID=$module ORDER BY itemid ASC  LIMIT $nums");
			while($r = $db->fetch_array($result)) {
                $linkId = $r['letter'];  //我这个是二开过的,拼音搜索为静态获取拼音
                //$linkId = $r['word'];    //官方是中文url就开启这个
                $linkurl = $dir."kw-".$linkId.".html";//定义模块URL
                $item.=$domain.$linkurl;
                $item .= "\r\n";;
    

			}
		}
}
$data .= $item;
$data = str_replace('><', ">\n<", $data);
file_put(DT_ROOT.'/sitemaps.txt', $data);
//关键词搜索记录结束
$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;
?>

  

  这样效果就出来了,演示图片:

   

 

 

 演示地址:http://www.sdfymj.com/sitemaps.txt

posted @ 2020-02-10 13:29  圆柱模板  阅读(195)  评论(0编辑  收藏  举报