Filtering one most recent record per category

14 posts by 5 authors in: Forums > CMS Builder
Last Post: June 8, 2010   (RSS)

By Jason - June 8, 2010

Hi,

This should be a pretty easy fix, I just need one point clarified first.
Do you need to limit the number of service titles per category, or the number of service titles in total? (ie, no more than 8 titles in a category, or no more than 8 titles at all?)

Let me know and we'll get this taken care of.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Filtering one most recent record per category

By studio-a - June 8, 2010

Hi Jason,

Thanks for asking. We will need to limit the number of Service Titles per category.

Your help is greatly appreciate!

studio-a

By Jason - June 8, 2010

Hi,

Okay, all we have to do is limit the number that we output. We can change our output code to this:

<?php $maxCount=8; ?>
<?php foreach($Services as $key=>$service): ?>
<?php if(is_array($service)): ?>
<ul>
<li><?php echo $categoryNumToName[$key];?></li>
<ul>
<?php $currentCount=0; ?>
<?php foreach($service as $item): ?>
<?php if($currentCount<$maxCount): ?>
<li><?php echo $item ?></li>
<?php $currentCount++; ?>
<?php endif ?>
<?php endforeach ?>
</ul>
</ul>
<?php endif ?>
<?php endforeach ?>


The variable $maxCount is set to whatever the maximum number of titles we want displayed per category. In this example, it's 8 but you can change that to whatever you want.

Give this a try and let me know how you make out.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/