• 【DIY文章列表标签】dt_gry_list


    需求是:文章列表 可以实现前几篇文章  带有 new 字样的图片或符号的 突出样式.. 

    可以通过如下方式修改 dt_list 标签 来实现...

    用JS 虽然也可以实现new 样式,但是并不灵活.. 只是特地情况下使用..

    这个标签可以实现,很多东西,比如 第一项,调用新闻缩略图, 第一项 调用 文章简介之类的样式..

    主要考虑灵活性.. 所以才在PHP 里面稍加改动...   当然这个改动也是很简单的...  会点PHP 的都会觉得这个很easy..   只是给新手看的哈.. 高手略过..

    现发出 我修改的 标签代码,感兴趣的用户  研究研究吧..  难度并不高,只是提供大家一个 修改标签的方法..  让大家享受DIY 的乐趣(这也是我喜欢SHLCMS 系统的原因,完全开源!感谢SHL团队组给我们带来这么好的CMS系统  )

    打开 content/index/list.php  加入 如下代码:

    本帖隐藏的内容需要回复才可以浏览

    1. function dt_gry_list($channelId,$n=0,$strcount=0,$stcountl=0,$style=0,$count=0,$prominent='gry',$isdate=true,$isellipsis=true,$ordering='ordering')
    2. {
    3.         global $db,$pfileName;
    4.         //file_exists(get_abs_skin_root().'index/list_'.$style.'.php') or die('dt_list 函数参数错误。没有找到 list_'.$style.'.php 文件');
    5.         if($n == 0)
    6.                 $results= $db->get_results("select * from ".TB_PREFIX."list as a,".TB_PREFIX."list_content as b  where a.guid=b.guid and a.channelId=$channelId order by a.".$ordering." desc");
    7.         else
    8.                 $results= $db->get_results("select * from ".TB_PREFIX."list as a,".TB_PREFIX."list_content as b  where a.guid=b.guid and a.channelId=$channelId order by a.".$ordering." desc limit $n");
    9.         if($results)
    10.         {
    11.                 $i=1;
    12.                 foreach($results as $o)
    13.                 {
    14.                         if(!$isellipsis&&$strcount>0)$o->title=cnSubstr($o->title,0,$strcount-1); //截取标题字数
    15.                         elseif($isellipsis&&$strcount>0&&cnStrLen($o->title)>$strcount)$o->title=cnSubstr($o->title,0,$strcount-1)."..";
    16.                         elseif($isellipsis&&$strcount>0&&cnStrLen($o->title)<$strcount)$o->title=$o->title;
    17.                         else $o->ptitle=$o->title; //保留完整标
    18.                                                 
    19.                         if(!$isellipsis&&$stcountl>0)$o->content=cnSubstr(strip_tags($o->content),0,$stcountl-1); //截取标题字数
    20.                         elseif($isellipsis&&$stcountl>0&&cnStrLen(strip_tags($o->content))>$stcountl)$o->content=cnSubstr(strip_tags($o->content),0,$stcountl-1)."..";
    21.                         elseif($isellipsis&&$stcountl>0&&cnStrLen(strip_tags($o->content))<$stcountl)$o->content=strip_tags($o->content);
    22.                         else $o->pcontent=$o->content; //保留完整标        
    23.                         if($isdate)
    24.                         {
    25.             if(date('Y-m-d',strtotime($o->dtTime))==date('Y-m-d'))
    26.                         {
    27.                         if($i<=$count)
    28.                         require(get_style_file('list',$prominent.'_'.$style));
    29.                         else
    30.                         require(get_style_file('list',$style));
    31.                         }
    32.                         else
    33.                         require(get_style_file('list',$style));
    34.                         }
    35.                         else
    36.                         {
    37.                         if($i<=$count)
    38.                         require(get_style_file('list',$prominent.'_'.$style));
    39.                         else
    40.                         require(get_style_file('list',$style));        
    41.                         }
    42.                         
    43.                         $i++;                        
    44.                 }
    45.         }
    46. }
    复制代码




    上面的是应用在 3.8 版本中的 代码,下面再发一个 4.0 版本的代码.. 其实区别不大,就是SQL 语句不同而已...

    本帖隐藏的内容需要回复才可以浏览

    1. function dt_gry_list($channelId,$n=0,$strcount=0,$stcountl=0,$style=0,$count=0,$prominent='gry',$isdate=true,$isellipsis=true,$ordering='ordering')
    2. {
    3.         global $db,$pfileName;
    4.         //file_exists(get_abs_skin_root().'index/list_'.$style.'.php') or die('dt_list 函数参数错误。没有找到 list_'.$style.'.php 文件');
    5.        if($n == 0)
    6.                 $results= $db->get_results("select * from ".TB_PREFIX."list_view where channelId=$channelId order by ".$ordering." desc");
    7.         else
    8.                 $results= $db->get_results("select * from ".TB_PREFIX."list_view  where channelId=$channelId order by ".$ordering." desc limit $n");
    9.         if($results)
    10.         {
    11.                 $i=1;
    12.                 foreach($results as $o)
    13.                 {
    14.                         if(!$isellipsis&&$strcount>0)$o->title=cnSubstr($o->title,0,$strcount-1); //截取标题字数
    15.                         elseif($isellipsis&&$strcount>0&&cnStrLen($o->title)>$strcount)$o->title=cnSubstr($o->title,0,$strcount-1)."..";
    16.                         elseif($isellipsis&&$strcount>0&&cnStrLen($o->title)<$strcount)$o->title=$o->title;
    17.                         else $o->ptitle=$o->title; //保留完整标
    18.                                                 
    19.                         if(!$isellipsis&&$stcountl>0)$o->content=cnSubstr(strip_tags($o->content),0,$stcountl-1); //截取标题字数
    20.                         elseif($isellipsis&&$stcountl>0&&cnStrLen(strip_tags($o->content))>$stcountl)$o->content=cnSubstr(strip_tags($o->content),0,$stcountl-1)."..";
    21.                         elseif($isellipsis&&$stcountl>0&&cnStrLen(strip_tags($o->content))<$stcountl)$o->content=strip_tags($o->content);
    22.                         else $o->pcontent=$o->content; //保留完整标        
    23.                         if($isdate)
    24.                         {
    25.             if(date('Y-m-d',strtotime($o->dtTime))==date('Y-m-d'))
    26.                         {
    27.                         if($i<=$count)
    28.                         require(get_style_file('list',$prominent.'_'.$style));
    29.                         else
    30.                         require(get_style_file('list',$style));
    31.                         }
    32.                         else
    33.                         require(get_style_file('list',$style));
    34.                         }
    35.                         else
    36.                         {
    37.                         if($i<=$count)
    38.                         require(get_style_file('list',$prominent.'_'.$style));
    39.                         else
    40.                         require(get_style_file('list',$style));        
    41.                         }
    42.                         
    43.                         $i++;                        
    44.                 }
    45.         }
    46. }
    复制代码




    这样你就可以在首页调用的时候 使用 
    <?php echo  dt_gry_list(1,5,20,0,0,[3,]['gry',][true,]true,'id')?>标签来调用此文章列表函数啦..(使用时 请把中括号去掉..)
    大家对比下 官方的 dt_list 标签就会发现 这个标签 多出两个可填参数 , 其他参数我就不介绍了,官方有标签说明,不知道的 新用户 可以去官方查阅 标签说明,

    我介绍下 我DIY 的这个标签 多出的两个 参数 ,一个是(3,) 这个标签的作用是 定义 你需要 调用出来的 文章列表 前几条 使用 特殊样式,比如 这个我填  3  ,意思就是 5条 文章 的前 3条 是有new 标识的..
    而('gry',)参数 ,相信大家也猜到了,就是在模板目录下index 风格目录下 你要调用的特殊样式文件的 文件名称style ,用以区分 list_style.php 
    ---------------6.30 跟新-----------------------
    根据 淡淡的建议,加入了一个更人性化的功能..日期限制,规则如下..

    比如你的首页 文章列表有5条,而你今天跟新了6条新闻,那么规则照旧,还是 按照原来的规则,会按照你标签 参数中输入的 前几条文章后面 显示 new  标识,
    但是 如果你今天只跟新了 1 条内容,而你的参数中输入的 确是前 3条显示new 标识的话,那 这个日期限制就会起作用了,他只会在你今天跟新的那一条文章标题后面显示new 符号..

    如果大家需要取消此日期限制的话,那么新增的 第三个参数 $isdate 就有用了,把他的值 设置为false ,此日期限制就会取消, 还是会按照你 标签参数的条数 显示new 标识....

    ----------------------------------------------

    调用之后,你可以在 模板目录下 index 标签风格目录下  新建一个 list_gry_0.php 来定义特殊样式的风格 

    比如你的list_0.php 代码可能是

    1. <?php
    2. if(URLREWRITE)
    3. {?>
    4. <!--如果采用URL重写,调用新闻链接地址形式如下:html/company/view_22.html,其中get_menuName()函数获得栏目或频道英语名称。-->
    5. <a href="<?php echo get_root_path() ?>/html/<?php echo get_menuName($o->channelId)?>/view_<?php echo $o->id ?>.html" class="zi2"><?php echo $o->title ?></a>
    6. <?php
    7. }
    8. else
    9. {?>
    10. <a href="<?php echo get_root_path()?>/?p=<?php echo $o->channelId ?>&a=view&r=<?php echo $o->id ?>" class="zi2"><?php echo $o->title ?></a>
    11. <?php
    12. }
    13. ?>
    复制代码

    那么你就可以在 list_gry_0.php 中 把此代码直接复制 进去 并加入你想要 显示出来的 new 标识,例如:

    1. <?php
    2. if(URLREWRITE)
    3. {?>
    4. <!--如果采用URL重写,调用新闻链接地址形式如下:html/company/view_22.html,其中get_menuName()函数获得栏目或频道英语名称。-->
    5. <a href="<?php echo get_root_path() ?>/html/<?php echo get_menuName($o->channelId)?>/view_<?php echo $o->id ?>.html" class="zi2"><?php echo $o->title ?></a><font color="red">new</font>
    6. <?php
    7. }
    8. else
    9. {?>
    10. <a href="<?php echo get_root_path()?>/?p=<?php echo $o->channelId ?>&a=view&r=<?php echo $o->id ?>" class="zi2"><?php echo $o->title ?></a><font color="red">new</font>
    11. <?php
    12. }
    13. ?>
    复制代码

    这样一系列操作下来..  你在首页调用新闻的时候就可以显示出来类似下面的样式:

    gry_list标签测试新闻列表1  new
    gry_list标签测试新闻列表2  new
    gry_list标签测试新闻列表3  new
    gry_list标签测试新闻列表4  
    gry_list标签测试新闻列表5  

    好了... DIY 自己的SHL 标签 的教程就到这了... 喜欢的一定要回个帖哦!!

  • 相关阅读:
    Vue 框架-09-初识组件的应用
    Vue 框架-08-基础实战 demo
    Vue 框架-07-循环指令 v-for,和模板的使用
    Vue 框架-06-条件语句 v-if 实现选项卡效果
    Vue 框架-05-动态绑定 css 样式
    Vue 框架-04-计算属性
    Vue 框架-03-键盘事件、健值修饰符、双向数据绑定
    MUI框架-14-使用自定义icon图标、引入阿里巴巴矢量图标
    在【此电脑】隐藏【设备和驱动器】中不需要的图标
    MUI框架-13-使用百度地图 API(图文教程)
  • 原文地址:https://www.cnblogs.com/wycc/p/2513499.html
Copyright © 2020-2023  润新知