List Filtering Question

4 posts by 3 authors in: Forums > CMS Builder
Last Post: June 19, 2009   (RSS)

Re: [greatjakes] List Filtering Question

By ross - June 18, 2009

Hi there.

Thanks for posting!

What stage are you at here? It's going to be best to break this down into smaller pieces.

I would start with getting a list of the years to appear down the left side. Once you get that going, we can figure out what the link should be.

Do you already have the years appearing? Let me know :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] List Filtering Question

By greatjakes - June 19, 2009

Hi Ross,
I'm having difficulty getting the years to appear on the left side. Tried putting below code, but it doesn't list all the years -
<?php foreach ($newsRecords as $record): ?>
<?php echo date("Y", strtotime($record['date'])) ?>
<?php endforeach; ?>

Can't seem to figure out what code would make the list to appear correctl. I would appreciate it if you can help me figure out how to get this to work, Thanks.

Re: [greatjakes] List Filtering Question

By Damon - June 19, 2009

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/