Jump to content

get date of post and display by monthly


jarvis

Recommended Posts

Hi,

 

I'm using Wordpress but think the priniciple is the same. I wish to get the date of a post for example:

<?php the_time(d M Y') ?>

Once I have the date I then need to list the posts bi-monthly:

Aug - Sept 11

- all posts with a aug - sept date

June - July 11

- all posts with a june - july date

Apr - May 11

Feb - Mar 11

Dec - Jan 11

- all posts with a dec 10 or jan 11 date

Oct - Nov 10

etc

 

Am at a total loss on how to do this? Is anyone able to point me in the right direction?

 

I thought I could get the month and year a post, then use a switch/case statement, problem is, I can't see how I would do the year part and equally the fact that it's dec 10 and jan 11

 

:-(

 

Any help is very much appreciated.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/245009-get-date-of-post-and-display-by-monthly/
Share on other sites

Sorry,

Just wondering if this is on the right lines:

<?php
$month = the_time('M');
$year = the_time('Y');

switch (true) {

case ($month == 'Aug' && $year == '2011') : 
	$heading = "Aug - Sept 11";
	break;
case ($month == 'Sept' && $year == '2011') : 
	$heading = "Aug - Sept 11";
	break;		

}
?>

If so, is there a way it can be auto generated? Otherwise I'd need to add a case for all months for the past X years and also cater for all future years?

 

Or is this miles off?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.