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: [MOD] Archives by Month and Year (sNews 1.4)  (Read 6377 times)

Luka

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 36
  • Posts: 1717
    • http://www.snewscms.com
[MOD] Archives by Month and Year (sNews 1.4)
« on: May 11, 2006, 10:43:57 pm »

Mod version: 0.9
For sNews version: 1.4

This is a rewritten archives function which displays articles by month and year.

Note: $month_names is an array containing the month names and I put it there for easy localization

Please backup your snews.php first!!!


Installation:

Locate archives funtion in your snews.php and replace it with this one:

Code: [Select]
// ARCHIVES
function archives() {
echo "

". l('archives') ."

";
$month_names = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December');
$query = "SELECT * FROM " .db('prefix'). "articles WHERE position = 1 AND published = 1 ORDER BY date DESC";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
$year = substr($r['date'], 0, 4);
$month = substr($r['date'], 5, 2);
$month_name = ( substr($month, 0, 1) == '0' ) ? $month_names[substr($month, 1, 1)] : $month_names[$month];
if ($last <> $year.$month) {
echo "

" .$month_name. ", " .$year. "

";
}
echo "

" .$r['title']. "

";
$last = $year.$month;
}
Logged

gomisan

  • Full Member
  • ***
  • Karma: 0
  • Posts: 194
    • http://fish-cam.net/
[MOD] Archives by Month and Year (sNews 1.4)
« Reply #1 on: May 12, 2006, 05:16:29 am »

Can you post a link showing sample output?
Logged
Check out my sNews powered Tropical Fishtank site, live Fish-Cam !!

bryn

  • Hero Member
  • *****
  • Karma: 2
  • Posts: 934
    • http://www.cssugly.com
[MOD] Archives by Month and Year (sNews 1.4)
« Reply #2 on: May 12, 2006, 08:52:16 am »

thanks Luka..I will get around to trying this and other Mods today..very useful especially for blog sites where that type of archive display is common..excellent :)

**must remember to backup snews.php as all these handy new Mods coming out mean lots of changes to the core files..anyone tested all of them together and found any conflicts yet? - perhaps we could have a repository for Modded snews.php files giving details of what changes each one has made to the core**

just an idea? ;)
Logged
Over 1,000 posts of joy, sNews is not only brilliant, but fun too! thanks guys :D

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD] Archives by Month and Year (sNews 1.4)
« Reply #3 on: May 29, 2006, 01:27:13 pm »

luka, please verify these changes
Quote
// ARCHIVES
function archives() {
    echo "

". l('archives') ."

";
    $month_names = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December');    
    //$query = "SELECT * FROM " .db('prefix'). "articles WHERE position = 1 AND published = 1 ORDER BY date DESC";
    //errata: wrong database prefix
    $query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 1 AND published = 1 ORDER BY date DESC";
    $result = mysql_query($query);
    while ($r = mysql_fetch_array($result)) {
        $year = substr($r['date'], 0, 4);
        $month = substr($r['date'], 5, 2);
        $month_name = ( substr($month, 0, 1) == '0' ) ? $month_names[substr($month, 1, 1)] : $month_names[$month];
            if ($last <> $year.$month) {
            echo "

" .$month_name. ", " .$year. "

";
            }
        echo "

" .$r['title']. "

";
        $last = $year.$month;
       //errata: missing parenthesis }
     }
}
EDIT: error resulting code highlighted for clarity
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

harry

  • Newbie
  • *
  • Karma: 1
  • Posts: 37
    • http://www.thebusinesscardshop.net/order/
[MOD] Archives by Month and Year (sNews 1.4)
« Reply #4 on: June 11, 2006, 02:01:02 pm »

Thanks for the mod!, got the second code posted by MIKA working

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD] Archives by Month and Year (sNews 1.4)
« Reply #5 on: June 11, 2006, 10:39:08 pm »

nice to see you're satisfied, harry ;)
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

heathrowintl

  • Newbie
  • *
  • Karma: 0
  • Posts: 25
[MOD] Archives by Month and Year (sNews 1.4)
« Reply #6 on: June 29, 2006, 03:35:02 pm »

hi. i pasted mika's code into my snews file, but i am using snews-txtdb, so it didn't work straight away, obvious errors about connection to mysql etc etc. so i modifed it and its working (for me anyway), so here is a snews-txtdb 1.4 version. i hope this is the right spot to paste it.


// ARCHIVES
function archives() {
   connect_to_db();
   $db = new Database(s('dbname'));
    echo "

". l('archives') ."

";
    $month_names = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December');  
    //$query = "SELECT * FROM " .db('prefix'). "articles WHERE position = 1 AND published = 1 ORDER BY date DESC";
    //errata: wrong database prefix
    $cat_query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 1 AND published = 1 ORDER BY date DESC";
    $cat_result = $db->query($cat_query);
    while ($r = $cat_result->fetch_array()) {
        $year = substr($r['date'], 0, 4);
        $month = substr($r['date'], 5, 2);
        $month_name = ( substr($month, 0, 1) == '0' ) ? $month_names[substr($month, 1, 1)] : $month_names[$month];
            if ($last <> $year.$month) {
            echo "

" .$month_name. ", " .$year. "

";
            }
        echo "

" .$r['title']. "

";
        $last = $year.$month;
       //errata: missing parenthesis }
     }
}
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • “I'm a self-made man and worships my creator.”
    • p-ahlqvist.com
[MOD] Archives by Month and Year (sNews 1.4)
« Reply #7 on: June 30, 2006, 09:37:19 am »

Heathrowintl... Not Darell, eh ?
Logged
"It's only dead fish that goes with the flow... "
Updated

Elvino

  • Newbie
  • *
  • Karma: 0
  • Posts: 44
    • http://www.elvino.it/
[MOD] Archives by Month and Year (sNews 1.4)
« Reply #8 on: July 05, 2006, 09:16:51 am »

This mod works well but it has a functionality problem:  with the time the page archives allonge too much…  
 
The ideal would be multiple pages archives, one for year or month!  
Otherwise the situated one web cannot be magnified too much in the time, remaining usable…    
Version 1,5 will have this functionality?    

Sorry for my bad english  :-P
thanks

Elvino

Elvino

  • Newbie
  • *
  • Karma: 0
  • Posts: 44
    • http://www.elvino.it/
[MOD] Archives by Month and Year (sNews 1.4)
« Reply #9 on: July 08, 2006, 12:28:06 am »

it does not interest to modification ?

;)

harry

  • Newbie
  • *
  • Karma: 1
  • Posts: 37
    • http://www.thebusinesscardshop.net/order/
[MOD] Archives by Month and Year (sNews 1.4)
« Reply #10 on: October 29, 2006, 03:56:24 am »

Did any pursue the suggestion by Elvino

To have archived articles

separated into months (which are clickable.)
i.e. Jan, Feb, Marc... clicking on those months would bring up pages posted in these months.

I have 10+ articles posted everyday, and the archive page is just unusable/unloadable and also takes an extremely long time to load.

By the way i'm using 1.4 stil.

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
[MOD] Archives by Month and Year (sNews 1.4)
« Reply #11 on: November 21, 2006, 02:38:27 am »

Quote from: Elvino
The ideal would be multiple pages archives, one for year or month!  
Otherwise the situated one web cannot be magnified too much in the time, remaining usable…    
Version 1,5 will have this functionality?
I'm interested to know if this is going to be developed for 1.5 as well  :)
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future