Split list into two divs on the same page

5 posts by 2 authors in: Forums > CMS Builder
Last Post: August 9, 2016   (RSS)

By MercerDesign - August 4, 2016

Hi, I followed this post (http://www.interactivetools.com/forum/forum-posts.php?postNum=2230025#post2230025) but I don't need the next and previous links, it doesn't work without them, I basically need the first two articles to display from a multi record list (latest_news), the first article to display in one div and the second to display in a different div. Thanks in advance.

By MercerDesign - August 8, 2016

Thanks that works but how can I make the two DIVS different, I want the first story to be in a larger DIV and the second one in a smaller sized one.

By Damon - August 8, 2016


Use two separate foreach loops to output each article so you can assign a separate div class or id to each:

<?php foreach ($sample_multi_recordRecords as $record): ?>
  <div id="one"> <?php echo htmlencode($record['title']) ?><br />
   Content: <?php echo $record['content']; ?><br/>
  <?php break; //only show first article ?>
<?php endforeach ?>

<?php $counter = 1; ?>
<?php foreach ($sample_multi_recordRecords as $record): ?>
  <?php if($counter == 2) : ?>
   <div id="two"> <?php echo htmlencode($record['title']) ?><br />
    Content: <?php echo $record['content']; ?><br/>
   <?php break; //only show second article ?>
  <?php endif; ?>
  <?php $counter++; ?>
<?php endforeach ?>

The first foreach loop breaks after displaying the first record. The second foreach loop uses a counter so it can pass the first record and use the if statement to match the number and display the second article, then break.

Hope this helps. Let me know if you have any other questions.

Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.

By MercerDesign - August 9, 2016

That's brilliant thanks. Works perfectly!