Re: [greatjakes] List Filtering Question
Hi,
You could just hard code the year links for the left nav but to have the year links automatically add new year links every year, here is some code to try:
<?php foreach ($newsRecords as $record): ?>
<?php $years[] = date("Y", strtotime($record['date'])) ?>
<?php endforeach; ?>
<?php $years = array_unique($years); ?>
<?php foreach ($years as $year): ?>
<a href="/news.php?date_year=<?php echo $year; ?>"><?php echo $year; ?></a> <br />
<?php endforeach; ?>
Make any changes to variables and array names as needed to match your setup.
The first foreach loop grabs just the article years and puts them into an array.
The next line uses the array_unique to put only years into the new array that are unique (so there will be no duplicates).
Then then final foreach loop outputs all the unique years including a search query link.
Let me know how that works for you.
Cheers,
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/