my Qbee PHP script
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
// 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.
comments powered by Disqus