Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: Rand Articles Links  (Read 1600 times)

NaEnr

  • Newbie
  • *
  • Karma: 10
  • Posts: 9
Rand Articles Links
« on: June 14, 2008, 11:24:13 pm »

Step 1: add code in snews.php:

Update 2008-06-15

Demo:


-----------------------------------------------------------------------------------------------------------
F5 Refresh Once
-----------------------------------------------------------------------------------------------------------


Code: [Select]
// RAND ARTICLES
function rand_articles($size) {
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 ORDER BY rand() LIMIT $size";
$result = mysql_query($query);
if (!$result || !mysql_num_rows($result)) {
echo '<li>'.l('no_articles').'</li>';
} else {
while ($r = mysql_fetch_array($result)) {
$categorySEF = find_cat_sef($r['category']);
$title = $r['category'] == 0 ? $home : retrieve('name', 'categories', 'seftitle', $categorySEF);
echo '<li><a href="'.db('website').$categorySEF.'/'.$r['seftitle'].'/" title="'.$r['title'].'">'.$r['title'].'</a></li>';
}
}
}

Step 1: add code in index.php

Code: [Select]
<?php rand_articles(5); ?>
« Last Edit: June 14, 2008, 11:34:04 pm by NaEnr »
Logged