Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Pages: [1] 2

Author Topic: [MOD] Popular articles (snews 1.5)  (Read 14822 times)

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD] Popular articles (snews 1.5)
« on: February 19, 2007, 09:50:38 AM »

Mandatory requirement: Page view counter mod.

Language variables (snews.php)
Quote
$l['posted_in'] = 'Posted in';
$l['views'] = 'Views';
New function (snews.php)
Quote
// POPULAR ARTICLES
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 '<ul>';
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 '<li><a href="'.db('website').$categorySEF.'/'.$r['seftitle'].'/" title="'.$r['title'].' - '.l('posted_in').' '.$categoryName.'">'.$r['title'].'</a> '.$r['views'].' '.l('views').'</li>';
}
#optional formatting (uncomment if needed)
//echo '</ul>';
}
Usage (index.php)
Quote
<!-- displaying top 5 popular articles -->
<!-- remove unordered list if using optional formatting (see comments above)-->

<ul>
<?php popular_articles(5);?>
</ul>
Live preview at www.ni5ni6.com
« Last Edit: October 10, 2008, 03:01:46 PM by Keyrocks »
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

bloop

  • Newbie
  • *
  • Karma: 0
  • Posts: 21
[MOD] Popular articles (snews 1.5)
« Reply #1 on: February 19, 2007, 02:43:59 PM »

Thank you very much , its so useful..
Logged

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[MOD] Popular articles (snews 1.5)
« Reply #2 on: March 04, 2007, 09:31:56 PM »

Mod added on my site without problems! :) Thank you Mika.
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
[MOD] Popular articles (snews 1.5)
« Reply #3 on: April 24, 2007, 06:30:11 PM »

I noticed it doesn't work if you have no reader.
My whole site is a bug !

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
[MOD] Popular articles (snews 1.5)
« Reply #4 on: April 24, 2007, 06:59:18 PM »

What do You mean - have no reader? And whole site a bug ... :lol:

P.S. Site looks great, btw ;)
Logged

mattonik

  • Full Member
  • ***
  • Karma: 7
  • Posts: 123
    • http://www.mattonik.sk
[MOD] Popular articles (snews 1.5)
« Reply #5 on: April 24, 2007, 07:12:38 PM »

nice mod, need to try it :)
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
[MOD] Popular articles (snews 1.5)
« Reply #6 on: April 26, 2007, 12:26:39 PM »

Quote from: codetwist
What do You mean - have no reader? And whole site a bug ... :lol:
It was a joke : but now it seems that this mod is not working on "my" sNews.  :(
Quote from: codetwist
P.S. Site looks great, btw ;)
Thanks mate.
Stil under construction but i's coming...  :cool:

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
[MOD] Popular articles (snews 1.5)
« Reply #7 on: April 26, 2007, 01:00:50 PM »

Have You applied that view counter mod that is required for this to work (like have view field in articles table, etc)?

I recall that I had their early versions running without problems.
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
[MOD] Popular articles (snews 1.5)
« Reply #8 on: April 26, 2007, 01:34:47 PM »

:|
Yes
but maybe something went wrong with the DB query.
I'll check later in the afternoon.
See you.  ;)

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
[MOD] Popular articles (snews 1.5)
« Reply #9 on: April 26, 2007, 03:11:48 PM »

:)
That's it !
Checking it back it seems that I have no table "PREFIX_articles".

EDIT : neither on my localhost :(

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
[MOD] Popular articles (snews 1.5)
« Reply #10 on: April 26, 2007, 03:19:06 PM »

Good :D
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
[MOD] Popular articles (snews 1.5)
« Reply #11 on: April 26, 2007, 03:58:11 PM »

:mad:
no good !
I can't alter a table which doesn't exist. !  :D

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] Popular articles (snews 1.5)
« Reply #12 on: April 26, 2007, 04:21:31 PM »

Quote from: Sven
:)
That's it !
Checking it back it seems that I have no table "PREFIX_articles".

EDIT : neither on my localhost :(
Where does it require a prefix to have been set??
If in the sql, ie,
Quote
SELECT * FROM ".db('prefix')."articles
, then, if you haven't used a prefix, it can't look for table PREFIX_articles, as db(prefix) will be empty...

It also means that you would use the standard query not the PREFIX_ query here
http://www.solucija.com/forum/viewtopic.php?pid=23166#p23166
to alter your article table
Logged
Of all the things I have lost, it is my mind that I miss the most.

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
[MOD] Popular articles (snews 1.5)
« Reply #13 on: April 26, 2007, 04:31:35 PM »

Okay Phil
you got  viagra for the brain ?
I think I need some.
 :D

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
[MOD] Popular articles (snews 1.5)
« Reply #14 on: April 26, 2007, 04:56:49 PM »

Quote from: Sven
:mad:
no good !
I can't alter a table which doesn't exist. !  :D
Ughhh ... sorry ... I thought that You solved it ... after all that was offending PREFIX right in Your post ;)
Logged
Pages: [1] 2