您的位置:首页 > 其它

【DIY文章列表标签】dt_gry_list

2012-05-22 16:23 218 查看
需求是:文章列表 可以实现前几篇文章 带有 new 字样的图片或符号的 突出样式..

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

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

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

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

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



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

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

function dt_gry_list($channelId,$n=0,$strcount=0,$stcountl=0,$style=0,$count=0,$prominent='gry',$isdate=true,$isellipsis=true,$ordering='ordering')

{

global $db,$pfileName;

//file_exists(get_abs_skin_root().'index/list_'.$style.'.php') or die('dt_list 函数参数错误。没有找到 list_'.$style.'.php 文件');

if($n == 0)

$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");

else

$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");

if($results)

{

$i=1;

foreach($results as $o)

{

if(!$isellipsis&&$strcount>0)$o->title=cnSubstr($o->title,0,$strcount-1); //截取标题字数

elseif($isellipsis&&$strcount>0&&cnStrLen($o->title)>$strcount)$o->title=cnSubstr($o->title,0,$strcount-1)."..";

elseif($isellipsis&&$strcount>0&&cnStrLen($o->title)<$strcount)$o->title=$o->title;

else $o->ptitle=$o->title; //保留完整标

if(!$isellipsis&&$stcountl>0)$o->content=cnSubstr(strip_tags($o->content),0,$stcountl-1); //截取标题字数

elseif($isellipsis&&$stcountl>0&&cnStrLen(strip_tags($o->content))>$stcountl)$o->content=cnSubstr(strip_tags($o->content),0,$stcountl-1)."..";

elseif($isellipsis&&$stcountl>0&&cnStrLen(strip_tags($o->content))<$stcountl)$o->content=strip_tags($o->content);

else $o->pcontent=$o->content; //保留完整标

if($isdate)

{

if(date('Y-m-d',strtotime($o->dtTime))==date('Y-m-d'))

{

if($i<=$count)

require(get_style_file('list',$prominent.'_'.$style));

else

require(get_style_file('list',$style));

}

else

require(get_style_file('list',$style));

}

else

{

if($i<=$count)

require(get_style_file('list',$prominent.'_'.$style));

else

require(get_style_file('list',$style));

}

$i++;

}

}

}

复制代码

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

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

function dt_gry_list($channelId,$n=0,$strcount=0,$stcountl=0,$style=0,$count=0,$prominent='gry',$isdate=true,$isellipsis=true,$ordering='ordering')

{

global $db,$pfileName;

//file_exists(get_abs_skin_root().'index/list_'.$style.'.php') or die('dt_list 函数参数错误。没有找到 list_'.$style.'.php 文件');

if($n == 0)

$results= $db->get_results("select * from ".TB_PREFIX."list_view where channelId=$channelId order by ".$ordering." desc");

else

$results= $db->get_results("select * from ".TB_PREFIX."list_view where channelId=$channelId order by ".$ordering." desc limit $n");

if($results)

{

$i=1;

foreach($results as $o)

{

if(!$isellipsis&&$strcount>0)$o->title=cnSubstr($o->title,0,$strcount-1); //截取标题字数

elseif($isellipsis&&$strcount>0&&cnStrLen($o->title)>$strcount)$o->title=cnSubstr($o->title,0,$strcount-1)."..";

elseif($isellipsis&&$strcount>0&&cnStrLen($o->title)<$strcount)$o->title=$o->title;

else $o->ptitle=$o->title; //保留完整标

if(!$isellipsis&&$stcountl>0)$o->content=cnSubstr(strip_tags($o->content),0,$stcountl-1); //截取标题字数

elseif($isellipsis&&$stcountl>0&&cnStrLen(strip_tags($o->content))>$stcountl)$o->content=cnSubstr(strip_tags($o->content),0,$stcountl-1)."..";

elseif($isellipsis&&$stcountl>0&&cnStrLen(strip_tags($o->content))<$stcountl)$o->content=strip_tags($o->content);

else $o->pcontent=$o->content; //保留完整标

if($isdate)

{

if(date('Y-m-d',strtotime($o->dtTime))==date('Y-m-d'))

{

if($i<=$count)

require(get_style_file('list',$prominent.'_'.$style));

else

require(get_style_file('list',$style));

}

else

require(get_style_file('list',$style));

}

else

{

if($i<=$count)

require(get_style_file('list',$prominent.'_'.$style));

else

require(get_style_file('list',$style));

}

$i++;

}

}

}

复制代码

这样你就可以在首页调用的时候 使用
<?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 代码可能是

<?php

if(URLREWRITE)

{?>

<!--如果采用URL重写,调用新闻链接地址形式如下:html/company/view_22.html,其中get_menuName()函数获得栏目或频道英语名称。-->

<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>

<?php

}

else

{?>

<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>

<?php

}

?>

复制代码

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

<?php

if(URLREWRITE)

{?>

<!--如果采用URL重写,调用新闻链接地址形式如下:html/company/view_22.html,其中get_menuName()函数获得栏目或频道英语名称。-->

<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>

<?php

}

else

{?>

<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>

<?php

}

?>

复制代码

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

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

好了... DIY 自己的SHL 标签 的教程就到这了... 喜欢的一定要回个帖哦!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: