sorting by date - for blog archives

5 posts by 4 authors in: Forums > CMS Builder
Last Post: February 2, 2012   (RSS)

Re: [Deborah] sorting by date - for blog archives

By Donna - September 19, 2008

Hi Deborah,

Thanks for your post. :) This isn't specifically a feature of CMS Builder so it's a little beyond what our support can normally handle... but we wanted to give it a try anyway so I think we've come up with some custom code that should make this work.

Here's the code I used:

<?php require_once "C:/wamp/www/cmsAdmin/lib/viewer_functions.php"; ?>

<?php
// get list of unique months and years with articles
$query = "SELECT DATE_FORMAT(date, '%M %Y') as dateAndYear, YEAR(date) as year, MONTH(date) as month FROM cms_blog GROUP BY dateAndYear ORDER BY date";
$result = mysql_query($query) or die("MySQL Error: ". htmlspecialchars(mysql_error()) . "\n");
while ($record = mysql_fetch_assoc($result)):
?>

<a href="blogList.php?date_year=<?php echo $record['year'] ?>&date_month=<?php echo $record['month'] ?>"><?php echo $record['dateAndYear']; ?></a><br/>

<?php endwhile ?>


Note: You'll want to replace the first "require_once" line with the correct path from your code generator, and also replace the table name (in my example, cms_blog) with the correct name, and the filename (where I've got blogList.php) with your list filename.

Put this in wherever you want your archive list to be, and that should do it. :)
Donna

--
support@interactivetools.com

Re: [Donna] sorting by date - for blog archives

By Deborah - September 19, 2008

Donna,

The code you provided does exactly what I was looking for! Many, many thanks to you and your team for going above and beyond to come up with this. I'm sure it will be helpful to others here in the forum, too. I now feel confident in offering CMS Builder as a solution for site blogs. (And for me personally, CMS Builder is far easier to style to match a site design than trying to customize blog software templates.)

Thanks once again for your superior customer support!

Deborah

Re: [Donna] sorting by date - for blog archives

By sidcam - September 14, 2010 - edited: September 14, 2010

Donna-

YOU ROCK!!!

THANK YOU! THANK YOU! THANK YOU!

That was about the only feature of my old Wordpress blog I hadn't figured out how to mimic.

Sid

Re: [Donna] sorting by date - for blog archives

By InHouse - February 2, 2012

Wow! That's so much more elegant that the kluge that I came up with ages ago.

This is a fairly popular client request - and standard in my 'frameworked' CMS tools. Might be worth exploring this type of structure as an option in the "List View Generator". At the very least, it should be collected into the Very Useful Archive of CMSB Recipes.

J.