Archives Issue

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 2, 2013   (RSS)

By design9 - March 26, 2013

Hello,

I have an archives section that I set up using a dropdown and it shows the month of year and then links to an archives page that I built that will show all records for that month based on date. I would like it to show up to 3 months worths of archives and not show the current month. Once the current month has passed, then I would like that to automatically be included in archives. 

So, my dropdown now should have December 2012, January 2013, February 2013 and not March 2013 since that is the current month. However, once April 2013 begins, then my dropdown should only have January, February and March 2013. 

I need help on the best way to accomplish this with the archives dropdown.

See my page:

http://www.charlotteparent.com/aboutus/advertising/tearsheet.php

I have uploaded my file with code.

Thanks!

April

Attachments:

tearsheet.php 13K

Hi April,

I think something similar to this post should work well:

http://www.interactivetools.com/forum/forum-posts.php?Array-of-months-from-today-78607

Here is how I would adapt your code:

<form>
  <select name="archive" size="1" onchange="loadPage(this.form.elements[0])" target="_blank" onmouseclick="this.focus()" style="background-color:#ffffff">
    <option value="">Select an Archive</option>
    <?php $i = 1; ?>
    <?php while($i < 4): ?>
      <?php $dateVal = strtotime('-'.$i.' month'); ?>
      <option value="http://www.charlotteparent.com/aboutus/advertising/archives.php?date_year=<?php echo date('Y', $dateVal); ?>&date_month=<?php echo date('n', $dateVal); ?>">
        <?php echo date('Y F', $dateVal); ?>
      </option>
      <?php $i++; ?>
    <?php endwhile ?>
  </select>
</form> 

So $i is used as a counter for the month. Then loop through each value for $i while it's less than 4. $i is then used to convert the month into a date value. This date value is used to display the month in various formats for each option.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com