Archives page - need unique heading from date field

5 posts by 2 authors in: Forums > CMS Builder
Last Post: August 9, 2009   (RSS)

By Deborah - August 7, 2009

I don't see a reference to this on the forum.

I'd like to display a heading on each archive page indicating the month and year of the records shown on that page. Example: "Archives for May 2009"

List viewer page displays archive records by month and year:

<?php // get list of unique months and years with articles
$query = "SELECT DATE_FORMAT(week_of, '%M %Y') as dateAndYear, YEAR(week_of) as year, MONTH(week_of) as month FROM cms_countywide_pdfs GROUP BY dateAndYear ORDER BY week_of"; $result = mysql_query($query) or die("MySQL Error: ". htmlspecialchars(mysql_error()) . "\n"); while ($record = mysql_fetch_assoc($result)): ?>
<li><a href="archives.php?date_year=<?php echo $record['year'] ?>&amp;date_month=<?php echo $record['month'] ?>"><?php echo $record['dateAndYear']; ?></a></li>

Clicking one of the links listed above goes to the archive page (list viewer), which displays the records for that month.

Now all I need is a heading (Month + Year).

Seems as if it should be simple, but I haven't figured it out. Does anyone have a suggestion?

Deborah

Re: [chris] Archives page - need unique heading from date field

By Deborah - August 8, 2009

Chris,

Thanks! That worked for me.

The date is therefore displayed as: 7 2009

Ideally, I'd like to see: July 2009, but I don't think that's possible. Unless you know of a way to do that, I'll be happy with the formatting as is.

I appreciate your help.
Deborah

Re: [Deborah] Archives page - need unique heading from date field

By Chris - August 9, 2009

Hi Deborah,

Practically anything is possible in PHP :)

<?php echo date("F", mktime(0, 0, 0, intval($_GET['date_month']), 10)) ?>
<?php echo htmlspecialchars($_GET['date_year'])?>


Please let us know if you have any more questions.
All the best,
Chris

Re: [chris] Archives page - need unique heading from date field

By Deborah - August 9, 2009

Chris,

You are brilliant! Thanks for that piece of code. It displays the month and year exactly as ordered!

Deborah