Hello

September 02, 2010, 05:02:16 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?
Login with username, password and session length
What sNews Is: - sNews is a simple, basic, customizable CMS tool suitable for developers with beginner-to-advanced PHP skills. It is also useful to have a good working knowledge of how to work with, set up and manage MySQL databases. sNews is not - geared towards the end-user who knows little or nothing about building and developing PHP-MySQL based websites.
News: Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: [MOD] Popular articles (snews 1.5)  (Read 10705 times)
Mika
Administrator
ULTIMATE member
******

Karma: 9
Posts: 1408


WWW
« 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


« 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! Smiley Thank you Mika.
Logged

Sven
ULTIMATE member
******

Karma: 76
Posts: 1853


Chasing MY bugs!


WWW
« 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
Hero Member
*****

Karma: 50
Posts: 955


« 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 Wink
Logged
mattonik
Full Member
***

Karma: 6
Posts: 121



WWW
« Reply #5 on: April 24, 2007, 07:12:38 PM »

nice mod, need to try it Smiley
Logged
Sven
ULTIMATE member
******

Karma: 76
Posts: 1853


Chasing MY bugs!


WWW
« 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.  Sad
Quote from: codetwist
P.S. Site looks great, btw Wink
Thanks mate.
Stil under construction but i's coming...  :cool:
Logged

codetwist
Hero Member
*****

Karma: 50
Posts: 955


« 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: 76
Posts: 1853


Chasing MY bugs!


WWW
« 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.  Wink
Logged

Sven
ULTIMATE member
******

Karma: 76
Posts: 1853


Chasing MY bugs!


WWW
« Reply #9 on: April 26, 2007, 03:11:48 PM »

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

EDIT : neither on my localhost Sad
Logged

codetwist
Hero Member
*****

Karma: 50
Posts: 955


« Reply #10 on: April 26, 2007, 03:19:06 PM »

Good Cheesy
Logged
Sven
ULTIMATE member
******

Karma: 76
Posts: 1853


Chasing MY bugs!


WWW
« Reply #11 on: April 26, 2007, 03:58:11 PM »

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

philmoz
High flyer
Administrator
ULTIMATE member
******

Karma: 152
Posts: 1843



WWW
« Reply #12 on: April 26, 2007, 04:21:31 PM »

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

EDIT : neither on my localhost Sad
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

Take offs are optional, landings are mandatory, unless you get into space, then you have other issues.
Sven
ULTIMATE member
******

Karma: 76
Posts: 1853


Chasing MY bugs!


WWW
« Reply #13 on: April 26, 2007, 04:31:35 PM »

Okay Phil
you got  viagra for the brain ?
I think I need some.
 Cheesy
Logged

codetwist
Hero Member
*****

Karma: 50
Posts: 955


« 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. !  Cheesy
Ughhh ... sorry ... I thought that You solved it ... after all that was offending PREFIX right in Your post Wink
Logged
Pages: [1] 2
  Print  
 
Jump to:  

English Steel 1.6 © Saxon North Technologies
Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!