How can I show a list of 4 then 4 again?

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

By (Deleted User) - June 8, 2010

Hello,

I am currently working on a latest news list on a home page. The list has 4 list items in it and there is some java to click left and right where another 4 display.

I would like to repeat the following with each foreach only putting 4 posts in - then do the complete code again with the next 4 etc.

<li>
<ul class="popular_posts_content">
<?php foreach($latest_newsRecords as $record): ?>
<!-- list 4 news items -->
<li>
<a href="/news/<?php echo $record['url_key'] ?>-<?php echo $record['num'] ?>"><img src="<?php echo $record['list_image_url_t'] ?>" width="60" height="60" alt="<?php echo $record['title'] ?>" class="alignleft"/></a>
<a href="#" class="title"><?php echo $record['title'] ?></a>
<a href="/news/<?php echo $record['url_key'] ?>-<?php echo $record['num'] ?>"><?php echo $record['link_text'] ?></a>
</li>
<!-- end of list 4 news items -->
<?php endforeach?>
</ul>
</li>


Any ideas?
Thanks Jono

Re: [jonoc73] How can I show a list of 4 then 4 again?

By Jason - June 8, 2010

Hi,

Could you give me an example of what you would want your final html to look like?

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: [jonoc73] How can I show a list of 4 then 4 again?

By Jason - June 8, 2010

Hi Jono,

This should accomplish what you're looking for:

<div class="sidebar_item_news">
<ul id="popular_posts">
<li>
<ul>
<?php $count=0; ?>
<?php foreach($latest_newsRecords as $record): ?>
<?php if($count==4): ?>
<?php $count=0; ?>
</ul>
</li>
<li>
<ul>
<?php endif ?>
<?php $count++; ?>
<li>
<a href="/news/<?php echo $record['url_key'] ?>-<?php echo $record['num'] ?>"><img src="<?php echo $record['list_image_url_t'] ?>" width="60" height="60" alt="<?php echo $record['title'] ?>" class="alignleft"/></a>
<a href="#" class="title"><?php echo $record['title'] ?></a>
<a href="/news/<?php echo $record['url_key'] ?>-<?php echo $record['num'] ?>"><?php echo $record['link_text'] ?></a>
</li>
<?php endforeach ?>
</ul></li>
</ul>
</div>


Give this a try and let me know.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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