ulfben. Version: 0.4 Author: Justin Tadlock Author URI: http://justintadlock.com License: GPL */ /** * ==ulfben== * This is a slightly modified Cleaner Gallery; * It supports excluding images from the gallery: [gallery exclude='id1,id2'] * It will display the image description (if available) instead of the title. (only tested with lightbox) * It will hide an excessive number of rows and allow you to hide/display them with a javascript effect * WP 2.7 sort order fix. ('orderby' => 'menu_order', //menu_order ID) */ /** * ===Notes=== * * This update is for WordPress 2.6+, which fixes some major issues. * This file takes the original gallery and outputs a cleaner valid XHTML gallery. * Caption links to attachment page if set in the image uploader. * If Lightbox-type scripts are off, the image links to the attachment page. */ /** * ===Tested with=== * * Lightbox 2 - http://www.huddletogether.com/projects/lightbox2/ * Slimbox - http://www.digitalia.be/software/slimbox * Thickbox - http://jquery.com/demo/thickbox/ * Lytebox - http://dolem.com/lytebox/ * Greybox - http://orangoo.com/labs/GreyBox/ * Lightview - http://www.nickstakenburg.com/projects/lightview/ * jQuery Lightbox Plugin (balupton edition) - http://www.balupton.com/sandbox/jquery_lightbox/ * jQuery Lightbox plugin - http://leandrovieira.com/projects/jquery/lightbox/ * Shutter Reloaded - http://www.laptoptips.ca/projects/wp-shutter-reloaded/ * Shadowbox - http://mjijackson.com/shadowbox/index.html */ /* * ===Code=== */ // Auto load Thickbox (included with WordPress)? // add_action('wp_head', 'thickbox_css'); // wp_enqueue_script('thickbox'); /** * jt_gallery_shortcode() * Creates a new gallery shortcode based on original * Integrate Lightbox-type scripts * * @since 0.1 */ function jt_gallery_shortcode($attr) { global $post; /************************************************ * Begin user-defined variables ************************************************/ /** * Users can set whichever Lightbox-type script * Just comment/uncomment whichever you'd like * Default is set to Lightbox/Slimbox */ // Lightbox or Slimbox? // jQuery Lightbox plugin(s)? $a_rel = "lightbox[cleaner-gallery-$post->ID]"; $a_class = "lightbox"; // Shutter? // $a_rel = "lightbox[cleaner-gallery-$post->ID]"; // $a_class = "shutterset_cleaner-gallery-$post->ID"; // Lytebox? // $a_rel = "lytebox[cleaner-gallery-$post->ID]"; // $a_class = "lytebox"; // Greybox? // $a_rel = "gb_imageset[cleaner-gallery-$post->ID]"; // $a_class = "greybox"; // Thickbox? // $a_rel = "clean-gallery-$post->ID"; // $a_class = "thickbox"; // Shadowbox // $a_rel = "shadowbox[cleaner-gallery-$post->ID]"; // $a_class = "shadowbox"; // Lightview? // $a_rel = "gallery[cleaner-gallery-$post->ID]"; // $a_class = "lightview"; // Link images to attachment page (no Lightbox) // $a_rel = false; // $a_class = false; // Show caption link? $cap_link = true; // Always show captions (use title if caption isn't defined)? $cap_always = false; // Number of rows to display 'till user expands the gallery. $visibleRows = 1; // Use post_content instead of title or caption, for display in the thickbox caption, and href title-property $useDescriptionAsTitle = true; /************************************************ * End user-defined variables ************************************************/ // We're trusting author input, so let's at least make sure it looks like a valid orderby statement if ( isset( $attr['orderby'] ) ) { $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); if ( !$attr['orderby'] ){ unset( $attr['orderby'] ); } } extract(shortcode_atts(array( 'order' => 'ASC', 'orderby' => 'menu_order', //menu_order ID 'id' => $post->ID, 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, //new default. 'size' => 'thumbnail', 'exclude' => '' ), $attr)); $exclude = explode(',',$exclude); $id = intval($id); $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'post__not_in' => $exclude) ); if ( empty($attachments) ){ return ''; } if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $id => $attachment ){ $output .= wp_get_attachment_link($id, $size, true) . "\n"; } return $output; } $itemtag = tag_escape($itemtag); $captiontag = tag_escape($captiontag); $columns = intval($columns); $itemwidth = $columns > 0 ? floor(100/$columns) : 100; //Remove the style output in the middle of the freakin' page. This needs to be added to the header //The width applied through CSS but limits it a bit $output = apply_filters('gallery_style', "\n";// Close gallery return $output; } /** * jt_gallery_css() * Function for outputting gallery CSS * * @hook wp_head */ function jt_gallery_css () { echo '' . "\n"; print ""; wp_enqueue_script('prototype'); wp_enqueue_script('scriptaculous-effects'); wp_enqueue_style('cleaner_gallery_css', get_bloginfo('wpurl') . '/wp-content/plugins/cleaner-gallery/cleaner-gallery.css', false, '0.4', 'screen'); wp_print_styles(array('cleaner_gallery_css')); } /** * thickbox_css() * Function for outputting the Thickbox CSS */ function thickbox_css() { wp_enqueue_style('thickbox', get_bloginfo('wpurl') . '/wp-includes/js/thickbox/thickbox.css'); wp_print_styles(array('thickbox')); } /** * Replace the old shortcode with new * Add CSS to header * CSS can be overwritten in theme stylesheets */ // Remove original gallery shortcode remove_shortcode(gallery); // Add a new shortcode add_shortcode('gallery', 'jt_gallery_shortcode'); // Get the CSS required and it to blog head add_action('wp_head', 'jt_gallery_css'); ?>