|
Mika
|
 |
« on: February 19, 2007, 09:50:38 AM » |
|
Mandatory requirement: Page view counter mod. Language variables (snews.php) $l['posted_in'] = 'Posted in'; $l['views'] = 'Views'; New function (snews.php) // 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) <!-- 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
|
|
|
|
bloop
Newbie
Karma: 0
Posts: 21
|
 |
« Reply #1 on: February 19, 2007, 02:43:59 PM » |
|
Thank you very much , its so useful..
|
|
|
|
|
Logged
|
|
|
|
David
sNews Dude
Hero Member
   
Karma: 7
Posts: 580
|
 |
« Reply #2 on: March 04, 2007, 09:31:56 PM » |
|
Mod added on my site without problems!  Thank you Mika.
|
|
|
|
|
Logged
|
|
|
|
|
Sven
|
 |
« 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 !
|
|
|
|
|
Logged
|
|
|
|
|
codetwist
|
 |
« 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: 6
Posts: 121
|
 |
« Reply #5 on: April 24, 2007, 07:12:38 PM » |
|
nice mod, need to try it 
|
|
|
|
|
Logged
|
|
|
|
|
Sven
|
 |
« Reply #6 on: April 26, 2007, 12:26:39 PM » |
|
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. P.S. Site looks great, btw  Thanks mate. Stil under construction but i's coming... :cool:
|
|
|
|
|
Logged
|
|
|
|
|
codetwist
|
 |
« 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
|
 |
« 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. 
|
|
|
|
|
Logged
|
|
|
|
|
Sven
|
 |
« 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 
|
|
|
|
|
Logged
|
|
|
|
|
codetwist
|
 |
« Reply #10 on: April 26, 2007, 03:19:06 PM » |
|
Good 
|
|
|
|
|
Logged
|
|
|
|
|
Sven
|
 |
« Reply #11 on: April 26, 2007, 03:58:11 PM » |
|
:mad: no good ! I can't alter a table which doesn't exist. ! 
|
|
|
|
|
Logged
|
|
|
|
philmoz
High flyer
Administrator
ULTIMATE member
    
Karma: 152
Posts: 1843
|
 |
« Reply #12 on: April 26, 2007, 04:21:31 PM » |
|
 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, 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#p23166to alter your article table
|
|
|
|
|
Logged
|
Take offs are optional, landings are mandatory, unless you get into space, then you have other issues.
|
|
|
|
Sven
|
 |
« Reply #13 on: April 26, 2007, 04:31:35 PM » |
|
Okay Phil you got viagra for the brain ? I think I need some. 
|
|
|
|
|
Logged
|
|
|
|
|
codetwist
|
 |
« Reply #14 on: April 26, 2007, 04:56:49 PM » |
|
:mad: no good ! I can't alter a table which doesn't exist. !  Ughhh ... sorry ... I thought that You solved it ... after all that was offending PREFIX right in Your post 
|
|
|
|
|
Logged
|
|
|
|
|