Bopo Posted April 18, 2009 Share Posted April 18, 2009 Hey Well basically I have created something very similar to the standard blog CMS's of there, however I would really like to generate archive categories (months, jan, feb, march, april etc), but the problem I'm having is how would I write it in such a way that when the 1st of May appears, May appears in the achive section, obviously it would be very easy to hard code all 12 months, but this would be very messy. Link to comment https://forums.phpfreaks.com/topic/154635-creating-achive-categories/ Share on other sites More sharing options...
Mchl Posted April 18, 2009 Share Posted April 18, 2009 I assume you have articles (or other content) stored in a database with dates on which they were published. It is easy then, to get a list of all year-month combinations for them. Link to comment https://forums.phpfreaks.com/topic/154635-creating-achive-categories/#findComment-813161 Share on other sites More sharing options...
Bopo Posted April 18, 2009 Author Share Posted April 18, 2009 Yeah I do The only method I can think of, is to have an if statement which basicallys evaluates if today is the first of May, June, July etc. If it is a sql query is executed which adds the month's name to the DB, and then some code works out a query based on the month Link to comment https://forums.phpfreaks.com/topic/154635-creating-achive-categories/#findComment-813178 Share on other sites More sharing options...
Mchl Posted April 18, 2009 Share Posted April 18, 2009 Nope: You would have a query like this: SELECT CONCAT(MONTH(publishDate),YEAR(publishDate)) FROM articles GROUP BY CONCAT(MONTH(publishDate),YEAR(publishDate)) (this example is pretty lousy, but demonstrates the idea) [edit] I hate my new keyboard... Link to comment https://forums.phpfreaks.com/topic/154635-creating-achive-categories/#findComment-813209 Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 @Mchl, your code is missing for me but I'd do something like: SELECT * FROM cms_table WHERE DATE_FORMAT(date_field, '%m-%Y') = '01-2009'; to get all articles from January 09. This is "bad" for MySQL as you're forcing it to format all dates in the cms table to find the ones it needs. A better way would be to have a field in that table formatted accordingly. Link to comment https://forums.phpfreaks.com/topic/154635-creating-achive-categories/#findComment-813212 Share on other sites More sharing options...
Mchl Posted April 18, 2009 Share Posted April 18, 2009 Well.. the task here was to get a list of months where articles were published... Getting list of articles is quite another thing. Link to comment https://forums.phpfreaks.com/topic/154635-creating-achive-categories/#findComment-813221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.