Joomla 热门新闻的有效期

     热门文章上的内容,是完全按照新闻点击次数排的。虽然原来发布的时候有个失效时间,但是大部分人懒得写,导致很旧的但是点击量大的新闻会长时间排在顶上,违背了新闻和热门的意思。
     因为这个原因,我想说不定能够设置一下,比如只显示两个月的新闻。但是看了一下那个热门新闻模块(mod_mostread),设置很简单,没这方面内容。
     于是只好改代码了么…… 打开/joomla/modules/mod_mostread.php,看见如下代码:

  • case 1:
  • default:
  • //Content Items only
  • $query = “SELECT a.id, a.title, a.sectionid, a.catid”
  • . \n FROM #__content AS a”
  • . \n LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id”
  • . \n INNER JOIN #__categories AS cc ON cc.id = a.catid”
  • . \n INNER JOIN #__sections AS s ON s.id = a.sectionid”
  • . \n WHERE ( a.state = 1 AND a.sectionid > 0 )”
  • . \n AND ( a.publish_up = ‘$nullDate’ OR a.publish_up <= ‘$now’ )”
  • . \n AND ( a.publish_down = ‘$nullDate’ OR a.publish_down >= ‘$now’ )”
  • . ( $access ? \n AND a.access <= $my->gid AND cc.access <= $my->gid AND s.access <= $my->gid” : )
  • . ( $catid ? \n AND ( a.catid IN ( $catid ) )” : )
  • . ( $secid ? \n AND ( a.sectionid IN ( $secid ) )” : )
  • . ( $show_front == “0” ? \n AND f.content_id IS NULL” : )
  • . \n AND s.published = 1″
  • . \n AND cc.published = 1″
  • . \n ORDER BY a.hits DESC”
  • ;
  • 那个case 1对应选项里的“只显示内容项目”,下面明显在构造SQL查询语句。<br />搜了一下,MySQL有个函数,DATEDIFF(),返回两个日期差的天数,这不是正好么。<br />在其中插入一句判断:

  • . \n AND ( DATEDIFF(‘$now’, a.created) <= 60 )”
  • 于是问题解决~ 这种脚本语言还真是容易学容易用……

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.