• 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 .= "
    ";
    //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
    
    //关键词搜索记录调取
    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 .= "
    ";;
        
    
    			}
    		}
    }
    $data .= $item;
    $data = str_replace('><', ">
    <", $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 .= "
    ";
    		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;
    ?>
    

      

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

       

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

  • 相关阅读:
    AJAX从后台接收的字符串如何与前台字符串比较
    ojdbc6.jar导入maven依赖失败(亲测有效)
    IDEA怎样创建maven项目
    yum下载rpm包以及相关依赖包
    pip离线安装包
    Python的print的底层实现
    django查询集-17
    django的数据库操作-16
    django数据库迁移-15
    django定义模型类-14
  • 原文地址:https://www.cnblogs.com/68xi/p/12290660.html
Copyright © 2020-2023  润新知