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>';

Recommended Answers

All 3 Replies

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++;
	}
?>

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 ++;
	
}
?>

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.