0

So I've developed some code to pull the latest 8 images from my flickr feed; however, I'm having trouble with figuring out how to do what I'm trying to do. Essentially, I need each 4th image to have a different <div> class (this helps with margins and what not). Any suggestions on how to get this working? Here's the code I have now which displays the 8 images in a row

foreach($images->photos->photo as $photo) {
        echo '<div><a href="http://flickr.com/photos/' . $flickr->username . '/' . $photo->attributes()->id . '"><img src="http://farm' . $photo->attributes()->farm . '.static.flickr.com/' . $photo->attributes()->server . '/' . $photo->attributes()->id . '_' . $photo->attributes()->secret . '_s.jpg"  width="55" height="55" alt="flickr"/></a></div>';
3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by jrotunda85
0

Try this.

<?
	$cnt = 1;
	foreach($images->photos->photo as $photo) 
	{	
		if($cnt==1 || (($cnt-1)%4==0))
			echo '<div>';
		
		echo '<a href="http://flickr.com/photos/' . $flickr->username . '/' . $photo->attributes()->id . '"><img src="http://farm' . $photo->attributes()->farm . '.static.flickr.com/' . $photo->attributes()->server . '/' . $photo->attributes()->id . '_' . $photo->attributes()->secret . '_s.jpg"  width="55" height="55" alt="flickr"/></a>';
		
		if($cnt==count($images->photos->photo) || $cnt%4==0)
			echo '</div>';
		$cnt++;
	}
?>
2

Or something a little more simple:

<?php
$n = 4; // the number you want to change
$i = 1;

foreach($images->photos->photo as $photo) {

	if ($i % $n == 0 ){
		echo '<div><a href="http://flickr.com/photos/' . $flickr->username . '/' . $photo->attributes()->id . '"><img src="http://farm' . $photo->attributes()->farm . '.static.flickr.com/' . $photo->attributes()->server . '/' . $photo->attributes()->id . '_' . $photo->attributes()->secret . '_s.jpg"  width="55" height="55" alt="flickr"/></a></div>';
	}else{
		// do something else
	}
	
	$i ++;
	
}
?>
0

Thank you both for the help! I ended up using PixelSoul's code with a little modfication and it's working perfectly! Thanks again!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.