jarvis Posted August 17, 2011 Share Posted August 17, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/245009-get-date-of-post-and-display-by-monthly/ Share on other sites More sharing options...
jarvis Posted August 17, 2011 Author Share Posted August 17, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/245009-get-date-of-post-and-display-by-monthly/#findComment-1258501 Share on other sites More sharing options...
@ Posted August 18, 2011 Share Posted August 18, 2011 im assuming your posts are stored in a database? if each post has a date that it was posted then you could sort them in from the database. If you post the table structure i'll have a better idea Quote Link to comment https://forums.phpfreaks.com/topic/245009-get-date-of-post-and-display-by-monthly/#findComment-1258967 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.