主页 > 网站建设 > 建站知识 > 【原创】DedeCms最新文章显示红色日期或加上new字

【原创】DedeCms最新文章显示红色日期或加上new字

POST TIME:2020-04-10 21:06

DedeCMS发布的文章显示红色日期或加上new字或new小图片,给近三天(或当天)发布的文章显示红色日期或加上new字或new小图片等,都是围绕pubdate做文章,写扩展的。

1、红色的日期


  1. [field:pubdaterunphp='yes']
  2. $a="<fontcolor=red>".strftime('%m-%d',@me)."</font>";
  3. $b=strftime('%m-%d',@me);
  4. $ntime=time();
  5. $day3=3600*24*3;
  6. if(($ntime-@me)<$day3)@me=$a;
  7. else@me=$b;
  8. [/field:pubdate]

2、红色的(new)


  1. [field:pubdaterunphp='yes']
  2. $aa=strftime('%m-%d',@me);
  3. $ntime=time();
  4. $tagtime=@me;
  5. $day3=3600*24*3;
  6. if($tagtime>$ntime-$day3)@me="<fontcolor='red'>(new)</font>";
  7. else@me=$aa;
  8. [/field:pubdate]

3、加new.gif小图片


  1. [field:pubdaterunphp='yes']
  2. $aa=strftime('%m-%d',@me);
  3. $ntime=time();
  4. $tagtime=@me;
  5. $day3=3600*24*3;
  6. if($tagtime>$ntime-$day3)@me="<imgsrc='new.gif'/>".$aa;
  7. else@me=$aa;
  8. [/field:pubdate]

要注意的问题是:如:"<img src='new.gif' />中不能用双引号,否则不行。

如果要给当天的高亮显示,把 3600 * 24 * 3 改为 3600 * 24  即可。

站长地带参考了上面的《DedeCms高亮显示:最新文章显示红色日期或加上new字或new小图片》,但是都是显示在最新文章后面的,而学员要求显示在文章的前面,于是做了适当的修改,亲测效果:

实现了最新发布文章在前面在NEWS图标背景效果。

此教程,以纳入VIP会员教程中,因为在实际情况用到的比较多。DedeCms高亮显示:最新文章显示红色日期或加上new字或new小图片。



收缩
  • 微信客服
  • 微信二维码
  • 电话咨询

  • 400-1100-266