A List of Months
3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 16, 2015 (RSS)
By Perchpole - March 16, 2015
Hello,
I'm trying to create an archive widget with 12 links representing each month. I would like the list to start from last month and run in reverse order. So (as we are currently in March) it would look like this...
- February
- January
- December
- November
- October
- etc...
- etc..
- March
Next month (April) March would jump from the bottom up to the top of the list.
Can anyone help?
Thanks,
Perch
By gkornbluth - March 16, 2015
Here's some code that I've used to create a list of months that might help
<select name="month">
<?php foreach(range(1,12) as $month): ?>
<option value="<?php echo $month;?> <?php selectedIf($month,@$_REQUEST['month']);?>"><?php echo date("F",strtotime("1985-$month-01 00:00:00"));?></option>
<?php endforeach ?>
</select>
There's also an interesting discussion at http://stackoverflow.com/questions/22735071/display-a-list-of-past-11-months-from-current-date
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php