Popular Articles

Popular Articles mod by Mika

Mandatory Requirement: Page View Counter

1. Language variables (snews.php)

$l['posted_in'] = 'Posted in';
$l['views'] = 'Views';

2. New function (snews.php)

function popular_articles($size) {
# select all published articles ordered by view column and limiting the output with numeric $size variable
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 ORDER BY views DESC LIMIT $size";
$result = mysql_query($query);
# "home" title defined outside while-loop
$home = s('home_sef');
#optional formatting (uncomment if needed)
//echo '
    while ($r = mysql_fetch_array($result)) {
    # find category SEF title (used to build links)
    $categorySEF = find_cat_sef($r['category']);
    # defining category name: if zero, we're at home, else retrieve category name
    $categoryName = $r['category'] == 0 ? $home : retrieve('name', 'categories', 'seftitle', $categorySEF);
    echo '
  • '.$r['title'].' '.$r['views'].' '.l('views').'
  • '; }
    #optional formatting (uncomment if needed)
    //echo '
'; }

Usage (index.php)

19.02.2007. 18:25


sNews requires PHP, MySQL and mod rewrite. If your server meets those requirements, get started and learn how to install sNews on your website in 3 easy steps.


Browse through our help center and learn about template tags and how to simply create your own theme. Dig into sNews and customize it to behave the way you want.


sNews can be a simple blog tool and a full blown CMS. Customize it with addons, mods or play with different themes.


Talk about sNews on our Forum and share your expirience.