Note: If you enjoy this article, you might also check out the Geeky Stuff section.
I'm a member of the Quilting Bee and I use a very simple PHP script I wrote for displaying my quilt. I figure someone else might get some use out of it, so here it is for your coding pleasure:
PHP
// The relative URL to the directory containing my patches
$img_dir = '/wp-images/qbee/';
// The patches in my quilt, arranged in an array of arrays
// such that each inner array contains the link URL, the
// patch file name, and the title of the patch (e.g. a
// member's name).
$patches = array(
array( 'http://www.theqbee.net', 'qbee.gif', 'Qbee home' ),
array( '/', 'mine.gif', 'My patch' ),
array( 'http://www.theqbee.net', '164.gif', 'My number' )
);
// The total patches in my quilt
$num_patches = count( $patches );
// Decide how many patches to show in a row. The idea
// is to show the patches arranged in a square; that is,
// each side should have the same number of patches.
$num_per_side = ceil( sqrt( $num_patches ) );
// Since each patch is 40 pixels wide and 40 pixels tall,
// we can decide how wide to make the quilt container,
// based on that and how many patches we want per side.
$quilt_width = 40 * $num_per_side;
// Contain the quilt within a paragraph of the determined
// container width. Also give it a position of 'relative' and
// an auto margin on either side so that it centers itself
// within the page. Embedded CSS, run away!!1
echo '<p style="width: ' . $quilt_width . 'px; margin: 10px auto; position: relative;">';
// Go through the patches and stick them in the paragraph.
foreach ( $patches as $count => $patch ) {
// Give more verbose variable names to each part of the
// current patch.
$url = $patch[0];
$image_name = $patch[1];
$title = $patch[2];
// Define the whole path to the patch image.
$image_url = $img_dir . $image_name;
// Display each patch
echo "<a href=\"$url\" title=\"$title\"><img src=\"$image_url\" alt=\"$title - $image_name\" width=\"40\" height=\"40\" /></a>";
// Stick in a line break if we've now got the right number
// of patches on this line.
if ( ($count + 1) % $num_per_side == 0 )
echo '<br />';
}
// Close our containing paragraph.
echo '</p>';
// Display the stats of how many patches are in the quilt.
echo "<p><em>$num_patches patches in my quilt</em></p>";
?>
I just embed the above code in my Qbee page. Since I use WordPress, I have to enable PHP for that page using the runPHP plugin.
Oh neat script, Sarah!