code to add in front.func.inc.php :
Code: Select all
function get_most_read_articles($template_default, $max_cnt_links=0, $dbcon) {
// find all new articles
$max_cnt_links = intval($max_cnt_links);
$limit = ($max_cnt_links) ? " LIMIT ".$max_cnt_links : "";
$sql ="SELECT article_id, count( article_id ) c
FROM ".DB_PREPEND."article_read_count
GROUP BY article_id
ORDER BY c DESC, date_read desc
$limit ";
$arr_id=array();
$arr_count=array();
if($result = mysql_query($sql, $dbcon)) {
$count_results = mysql_num_rows($result); $count = 0;
while ($row = mysql_fetch_row($result))
{
array_push($arr_id, $row[0]);
$arr_count[$row[0]]= $row[1];
}
reset($arr_id);
$new_links = "";
$count_results = count($arr_id); $count = 0;
while (list($k,$v)=each($arr_id))
{
$sql = "SELECT article_id, article_title, article_cid, UNIX_TIMESTAMP(article_tstamp) AS article_date ".
"FROM ".DB_PREPEND."phpwcms_article WHERE ".
"article_public=1 AND article_aktiv=1 AND article_deleted=0 AND ".
"article_begin < NOW() AND article_end > NOW() and article_id = ". $v ;
// new articles list
$target = ($template_default["link_target"]) ? ' target="'.$template_default["link_target"].'"' : "";
if($result = mysql_query($sql, $dbcon)) {
while ($row = mysql_fetch_row($result)) {
$count++;
if($template_default["link_length"] && strlen($row[1]) > $template_default["link_length"]) {
$article_title = substr($row[1], 0, $template_default["link_length"]).$template_default["cut_title_add"];
} else {
$article_title = $row[1];
}
/*if(trim($template_default["date_format"])) {
$article_title = international_date_format(
$template_default["date_language"],
$template_default["date_format"],
$row[3]).$article_title;
}*/
$article_title = "• " . $article_title ;
$show_count = $arr_count[$row[0]] . " readers";
$new_links .= $template_default["link_before"].$template_default["link_symbol"];
$new_links .= '<a href="index.php?id='.$row[2].','.$row[0].',0,0,1,0"';
$new_links .= $target." title='$show_count' alt='$show_count'>".html_specialchars($article_title)."</a>";
//try to remove possible unwanted after - if not enclosed before.link.after
if($new_links && !$template_default["link_before"] && $count < $count_results) {
$new_links .= $template_default["link_after"];
}
}
mysql_free_result($result);
}
}
}
//enclose whole
if($new_links) $new_links = $template_default["before"].$new_links.$template_default["after"];
return $new_links;
}
Code: Select all
// most read article sorted by popularity
if( ! ( strpos($content["all"],'{MOST_READ:')===false ) ) {
$content["all"] = preg_replace('/\{MOST_READ:(\d+)\}/e','get_most_read_articles($template_default["news"],$1,$db);',$content["all"]);
}
the template for that one is :
(place in left field in template admin)
Code: Select all
<br>
<img src="img/leer.gif" width="1" height="5">
<table cellspacing=0 cellpadding=0 border=0><tr><td><table bgcolor=cccccc cellpadding=0 cellspacing=0 width=100%><tr><td bgcolor=cccccc><img src="img/leer.gif" width="1" height="1"></td></table></td><tr><Th bgcolor=#faffea height=20>Most popular</th><tr><td><img src="img/leer.gif" width="1" height="1"></td><tr><td><table bgcolor=cccccc cellpadding=0 cellspacing=0 width=100%><tr><td bgcolor=cccccc><img src="img/leer.gif" width="1" height="1"></td></table></td><tr><td><table><tr><td>{MOST_READ:5}</td></table></td><tr><td><img src="img/leer.gif" width="1" height="1"></td><tr><td><table bgcolor=cccccc cellpadding=0 cellspacing=0 width=100%><tr><td bgcolor=cccccc><img src="img/leer.gif" width="1" height="1"></td></table></td></table>