sorting by date - for blog archives
5 posts by 4 authors in: Forums > CMS Builder
Last Post: February 2, 2012 (RSS)
I would like all blog posts for the past 30 days to appear on the active blog page. Any posts dated 31 days or older, to be archived and categorized by month. For example, I'd have in the left or right column of the page:
ARCHIVES
July 2008 (links to all posts for this month)
June 2008 (links to all posts for this month)
May 2008 (links to all posts for this month)
I can figure out how to filter the active blog page to show only the past 30 days, but I don't know how to set up the archives as shown above. It seems that this link generation could be automated using some PHP date code, but I'm not familiar enough with PHP to know how to do this. Can anyone provide an example?
Re: [Deborah] sorting by date - for blog archives
By Donna - September 19, 2008
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. :)
--
support@interactivetools.com
Re: [Donna] sorting by date - for blog archives
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
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
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.