- <?php
- /*
- Plugin Name: Virgo
- Plugin URI: http://jamietalbot.com/wp-hacks/virgo/
- Description: Mini photo switcher for WordPress.<br />Licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a>, Copyright © 2006 Jamie Talbot.
- Version: 0.1
- Author: Jamie Talbot
- Author URI: http://jamietalbot.com/
- CME, simple first pass at image switcher.
- Instructions:
- * Write a post and use the upload section of the post page to upload photos.
- * Give your images a title of linked_image_1, linked_image_2, etc. and a sensible description. You can
- change 'linked_image' to something else - see below.
- * Save your post.
- * In your theme file, inside the loop (just before the_content(); is a good place), place virgo();
- * When you load up your page, you'll see the first image large, plus thumbnails underneath. Clicking
- on the thumbnails will load the full picture in the main section.
- * Use the classnames below (virgo_container, virgo_main_photo, virgo_photo_stream) and CSS to integrate
- it into your theme.
- Any questions, let me know,
- Jamie.
- */
- // This is the maximum number of thumbnails that will be selected for each post.
- define ('VIRGO_MAX_PHOTOS', 5);
- // This is the prefix of your photo titles - you can change this to whatever you like, but once you
- // have decided on a prefix, you should stick to it otherwise you'll lose links you've already created.
- define ('VIRGO_IMAGE_PREFIX', 'linked_image');
- // This is some example CSS, change it to whatever you like. Put it in your theme's main
- // style.css instead if you want.
- ?>
- <style type="text/css">
- .virgo_container {
- background: #000;
- border-top: 1px solid #000;
- border-left: 1px solid #000;
- border-right: 1px solid #000;
- border-bottom: 1px solid #000;
- }
- #virgo_main_photo {
- margin: 10px auto;
- display: block;
- border: 4px solid #fff;
- }
- .virgo_thumb_photo {
- border: 4px solid #fff;
- margin-left: 5px;
- padding: 0;
- }
- </style>
- <?php
- function virgo () {
- global $wpdb, $post;
- if ($photos = $wpdb->get_results("SELECT guid AS file, post_title AS title, post_content AS description FROM $wpdb->posts WHERE post_status = 'attachment' AND post_parent = $post->ID AND post_title LIKE '" . VIRGO_IMAGE_PREFIX ."%' LIMIT " . VIRGO_MAX_PHOTOS)) {
- ?>
- <script type="text/javascript">
- function virgo_switch(url, title) {
- document.getElementById('virgo_main_photo').src = url;
- document.getElementById('virgo_main_photo').title = title;
- }
- </script>
- <div class="virgo_container">
- <div class="virgo_main_photo">
- <img id="virgo_main_photo" src="<?php echo $photos[0]->file ?>" title="<?php echo $photos[0]->description ?>" alt="<?php echo $photos[0]->title ?>" />
- </div>
- <div class="virgo_photo_stream">
- <?php
- foreach ($photos as $photo) {
- $thumb = substr($photo->file, 0, ($period = strrpos($photo->file, '.') + 1)) . 'thumbnail' . substr($photo->file, $period - 1);
- ?>
- <img class="virgo_thumb_photo" onclick="virgo_switch('<?php echo $photo->file ?>', '<?php echo $photo->description ?>')" src="<?php echo $thumb ?>" title="<?php echo $photo->description ?>" alt="<?php echo $photo->title ?>" />
- <?php
- }
- ?>
- </div>
- <span style="float: right;"><a href="http://jamietalbot.com/wp-hacks/virgo/" title="Powered by Virgo" style="color: #fff;">Virgo</a></span>
- <div style="clear: both"></div>
- </div>
- <?php
- }
- }
- ?>
Posted by Anonymous on Wed 17th Jan 06:03
download | new post
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.