Show 3 blog entries followed by 3 photos, then 3 blog entries, then 3 photos

quite new to PHP and I'm trying to get my page to show 3 blog entries, followed by 3 photos, followed by another 3 blog entries and so on and soforth.I've been recommended using do while loops but having a hard time getting it working or even getting my head round it, have been more used to using foreach loops in the CMS.This was my original code which would work but only if I explicitly added each loop by hand!\[code\] <?php // Show 3 blog entries$entries = $page->children("sort=-sort, limit=3");$count = 0;foreach ($entries as $entry) { $count++; $class = "blog_box"; if ($entry == $entries->last()) {$class .= " blog_box_last"; }if ($entry == $entries->first()) {$class .= " blog_box_first"; }if (0 == $count % 2) { $class .= " blog_box_even"; }?><div class="<?php echo $class; ?>"><div class="blog_text"><h3><?php echo $entry->title; ?></h3><h6><?php echo $entry->entry_date; ?></h6><p><?php echo $entry->body; ?></p></div><!-- /.blog_text --><?php if ($entry->image) { $image = $entry->image->width(350);?><img src="http://stackoverflow.com/questions/10294950/<?php echo $image->url; ?>" width="<?php echo $image->width; ?>" alt="<?php echo $entry->title; ?>" /><?php } ?><div class="clear"></div><!-- /.clear --></div><!-- /.blog_box --><?php }?>// Show 3 blog images<?php $blog_images = $page->get("image_uploads")->find("limit=3");foreach ($blog_images as $img) { $b_img = $img->size(200,140); ?><img src="http://stackoverflow.com/questions/10294950/<?php echo $b_img->url; ?>" width="<?php echo $b_img->width; ?>" height="<?php echo $b_img->height; ?>" alt="<?php echo $b_img->description; ?>" class="small_frame" /><?php } ?>\[/code\]The CMS developer kindly tried some code for me but I couldn't get it to work for me:\[code\] $entries = $page->children("sort=-sort");$images = $page->get("/image_uploads/"); $cnt = 0;do { $cnt++; $entry = $entries->shift(); if($entry) { // output 1 entry } if($cnt == 3) { while(++$cnt <= 6) { $image = $images->shift(); if($image) { // output 1 image } } $cnt = 0; }} while(count($entries) && count($images));\[/code\]I'm using ProcessWire.Thanks in advance guys!
 
Back
Top