Welcome, Guest. Please login or register.
Did you miss your activation email?
11 May 2008, 21:43

Login with username, password and session length
Home Chat Help Search Calendar Login Register
Pages: [1]
Print
Author Topic: News module - Most Popular news feature  (Read 1017 times)
0 Members and 1 Guest are viewing this topic.
fritzfs
Forum Member
*

Karma: -1
Offline Offline

Posts: 9


« on: 11 Feb 2008, 08:38 »

Hello guys,
I've made changes in CMSms to support Most Popular News feature. It works by counting the hits on news.

1) execute this SQL in your CMSms database:
Code:
ALTER TABLE `cms_module_news` ADD `hits` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0';

2) edit file Modules/News/action.detail.php:
Just after this code:
Code:
if ($row)
{
$onerow = new stdClass();
add this code:
Code:
$sql = "UPDATE ".cms_db_prefix()."module_news SET hits=hits+1 WHERE news_id = ".
$row['news_id'];
$db->Execute($sql);

3) create UDT that will display most popular news:
Code:
global $gCms;

$db = &$gCms->db;

$result = array();

$q = "SELECT news_title FROM `cms_module_news` ORDER BY hits DESC LIMIT 5";

$dbresult = $db->Execute( $q );
if( $dbresult ) {
    while ( $row = $dbresult->FetchRow() ) {
        array_push($result, $row['news_title']);
    }
}

echo implode(",", $result);
Logged
Sven
Guest
« Reply #1 on: 04 Mar 2008, 02:38 »

Thanks for sharing, pal.
Gonna try it soon.
Logged
calguy1000
Posts that don't follow the rules (don't ask what the rules are, read them) will be ignored, moved or deleted
Dev Team Member
Power Poster
*****

Karma: 141
Offline Offline

Posts: 3456

Location: Calgary, Canada



WWW
« Reply #2 on: 04 Mar 2008, 08:19 »

This can be done with no hacking to the news databases or php code.  You could use the news extra field, and a simple UDT that you call from your detail template to update the news_extra field for that article.
Logged

----
CMS Made Simple is Simple - For experienced developers.   You don't need to know php to use CMS but you should have some experience with website design, website development, and supporting dynamic applications in a hosted environment.   The words CSS, XHTML, and permissions should not be new to you.
kazkas
Forum Member
*

Karma: 1
Offline Offline

Posts: 83

Location: Telford, GB



« Reply #3 on: 26 Mar 2008, 06:51 »

The way I think it should be:

showcounts UTD:
Code:
global $gCms;
$db = &$gCms->db;
$id = $gCms->smarty->_tpl_vars['entry']->id;
$query = "UPDATE `cms_module_news` SET news_extra=IF(ISNULL(news_extra),1,1+news_extra) WHERE `news_id`=$id";
echo $query;
$rez = $db->Execute($query);

most_popular UDT:

Code:
global $gCms;
$db = &$gCms->db;
$result = array();
$q = " SELECT * FROM `cms_module_news` ORDER BY ( 1 + news_extra ) DESC LIMIT 5 ";
$dbresult = $db->Execute( $q );
if( $dbresult ) {
    while ( $row = $dbresult->FetchRow() ) {
      $onerow = new stdClass();
      $onerow->title = $row['news_title'];
      $onerow->id = $row['news_id'];
      $onerow->views = $row['news_extra'];
      $result[] = $onerow;
    }
}
$gCms->smarty->assign("most_popular", $result);

add {showcounts} to your detail template, and in the template you want to add most popular news, just add:

Code:
{most_popular}
<ol>
{foreach from=$most_popular item=entry}
    <li>{$entry->id}{$entry->title}, {$entry->views} views</li>
{/foreach}
</ol>

Logged
Pages: [1]
Print
Jump to: