News Page: One List or Three?

4 posts by 2 authors in: Forums > CMS Builder
Last Post: June 10, 2010   (RSS)

By Perchpole - June 10, 2010 - edited: June 10, 2010

Imagine a news page with lots of stories. There are 3 tiers - each presented using different formatting:

1) The top story occupies a position of prominence complete with a big headline.

2) The second and third stories are slightly less prominent but still bold.

3) The remaining stories fill in the bottom of the page.

The issue is, how do I use clean php to feed the right stories into the right tiers? I assume I would use a list and a corresponding foreach loop for each tier...

The first headline is pretty straight forward. You would simply add a limit of 1 to the returned list.

The second and third stories are more complex. I need to say, list all the stories apart from the first one and nothing after the 3rd one! (NB: I've tried doing this with greater-than and less-than expressions and it gets really clunky!)

For the remaining stories its a case of saying, list everything excluding the first 3 items.

You get the idea!

I have achieved this - but with some very clumsy code. I'm sure there must be a much cleaner, more ingenious way of doing things?

:0)

Perch

Re: [Perchpole] News Page: One List or Three?

By Jason - June 10, 2010

Hi,

I think the easiest way to accomplish this would be to select all of the stories first. Then have a counter that get's incremented after each story is outputted. You can then do your output with a simple if statement. Something similar to this:

<?php if($count==1): ?>
*OUTPUT TOP STORY*
<?php elseif($count>1 && $count<4): ?>
*OUTPUT FOR STORY 2 AND 3 *
<?php else: ?>
*OUTPUT FOR EVERYTHING ELSE*
<?php endif ?>
<?php $count++; ?>


This would work if you set $count=1 before you started your foreach loop and incremented it (<?php $count++?> )at the end of the loop.

Hope this points you in the right direction. If you run into any issues, please attach the .php file you're working with.
---------------------------------------------------
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: [Perchpole] News Page: One List or Three?

By Jason - June 10, 2010

Hi Perch,

Glad that's working for you.

The counter is great for (other than just counter), any situation where you need to know where you are in a list.

A lot of people use it to break up content at certain intervals (ie, make a new column after every X number of records).
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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