Jump to content

Creating Achive Categories


Bopo

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

@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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.