scrape flickr pics (two) cute apes

Now, ungodly ones,
I am gonna tame the wild apes a bit and put them in a cage

I make a DIV and call it the Zoo
and make a table in the zoo
and for the table-cells (“ApesCage”) and images in the cells i apply some extra styles.

[ad#banner-1]

I ripped a css-sheet and worked it around a bit,

.ApesZoo {
	position: relative;
}

.ApesZoo table {
	padding: 0px;
	margin: 0px;
	border: 0px;
}

.ApesCage {
	overflow: hidden;
	width: 60px;
	height: 36px;
	border: 1px solid #fff;
	padding-top: -3px;
}

.ApesCage img {
	margin-top: -6px;
	width: 60px;
	height: 45px;
	border: 0px;
}

Nice, now I put the DIV and TABLE tags and the “CLASS=Apes…” markers in the PHP file, and let her rip

$perrow=5;
$total_images=10;
$mytag="apes";

$flikker = join("",file("http://api.flickr.com/services/feeds/photos_public.gne?tags=$mytag&format=rss"));
$flikkerhits = preg_split('/img src="\;/', $flikker, -1, PREG_SPLIT_OFFSET_CAPTURE);
$max=count($flikkerhits);

$i=0;
$currentcolumn=1;
$rows=round($total_images/$perrow);
$currentrow=1;
echo "
"; echo ""; foreach($flikkerhits as $flikkerhit){ $i++; if($i>1) { echo ""; $currentcolumn++; if($currentcolumn>$perrow) { $currentcolumn=1; $currentrow++; if($currentrow>$rows) { break; } else { echo ""; } } } } echo "
"; echo ""; echo "
";

then you get something like this, works fine for me

I moved the width and height specs to the stylesheet, I am gonna be sorry about that later on, but lets just move on to part three, stuff the zoo on the wordpress sidebar

Posted in php, tool and tagged .

Leave a Reply

Your email address will not be published. Required fields are marked *