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.

Author Topic: Listing new articles by category  (Read 1022 times)

caesar

  • Guest
Listing new articles by category
« on: August 02, 2007, 07:42:38 pm »

Does anyone know how to list new articles per category instead of a mix of all categories?

I have already reviewed the Tips and trix doc and think that this can be done with an if statement like this
Code: [Select]
if ( get_id('article') == 'biology' ) {
echo 'Viewing article BIOLOGY';
}
?>
but I am not sure and I couldn't find an example on the forums.  


Example I have two categories, Blog & DIY:

New Blog articles
  Article one
  Article two
  Article three

New DIY articles
  Article one
  Article two
  Article three
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Listing new articles by category
« Reply #1 on: August 02, 2007, 08:10:50 pm »

I haven't needed this feature before so I haven't explored it. However, you will find the clues as to how this is done by examining this section of code (the lower half) of the //SITEMAP function in the snews.php file. This is the part of that function that displays the articles by category from the database. You could try creating a new function with this (in snews.php) and call it into your index.php file by using a PHP function-call statement using the function name... same structure as the other call-statements. Only one drawback though... this will list ALL articles in ALL categories... so you will need to figure out how to limit the number of articles displayed if you don't want the list to get too long.

Quote
echo '';
    $cat_query = "SELECT * FROM ".db('prefix')."categories WHERE published = 'YES' ORDER BY catorder";
    $cat_result = mysql_query($cat_query);
    while ($c = mysql_fetch_array($cat_result)) {
        echo '

'.$c['name'].'

';
        $catid = $c['id'];
        $query = $art_query." AND category = $catid ORDER BY id DESC";
        $result = mysql_query($query);
        echo '
    ';
            while ($r = mysql_fetch_array($result)) {
                $date = date(s('date_format'), strtotime($r['date']));
                echo $link.$c['seftitle'].'/'.$r['seftitle'].'/" title="'.$r['title'].'">'.$r['title'].'';
            }
            echo '
';
}
}
This is the part of function sitemap
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU