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
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
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: [Jason] How can I show a list of 4 then 4 again?
By (Deleted User) - June 8, 2010 - edited: June 8, 2010
<div class="sidebar_item news">
<h3>Latest News</h3>
<ul id="popular_posts">
<!-- FIRST LIST OF 4 NEWS ITEMS -->
<li>
<ul class="popular_posts_content">
<?php foreach($latest_newsRecords as $record): ?>
<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>
<!-- END OF FIRST LIST OF 4 NEWS ITEMS -->
<!-- START OF SECOND LIST OF 4 NEWS ITEMS WITHOUT PHP CODE-->
<li>
<ul class="popular_posts_content">
<li>
<img src="/news/popular_2.gif" width="60" height="60" alt="News Post" class="alignleft" />
<a href="#" class="title">Best iPhone apps of all time</a>
</li>
<li>
<img src="/news/popular_1.gif" width="60" height="60" alt="News Post" class="alignleft" />
<a href="#" class="title">Interview with Constantin Potorac</a>
</li>
<li>
<img src="/news/popular_4.gif" width="60" height="60" alt="News Post" class="alignleft" />
<a href="#" class="title">Official Iron Man 2 trailer released!</a>
</li>
<li>
<img src="/news/popular_3.gif" width="60" height="60" alt="News Post" class="alignleft" />
<a href="#" class="title">Can Avatar sweep all the Oscar awards?</a>
</li>
</ul>
</li>
<!-- END OF SECOND LIST OF 4 NEWS ITEMS WITHOUT PHP CODE-->
</ul>
<!-- Java buttons to nudge to next and previous 4 news items -->
<ul id="pop_nav">
<li id="prev_pop" class="sprite"></li>
<li id="next_pop" class="sprite"></li>
</ul>
<!-- End of Java buttons to nudge to next and previous 4 news items -->
</div>
Thanks Jono
Re: [jonoc73] How can I show a list of 4 then 4 again?
By Jason - June 8, 2010
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/