array( 'Thumbnail', 'post_thumbnail' ), 'post_id' => $post->ID, 'attachment' => true, 'the_post_thumbnail' => true, // WP 2.9+ image function 'default_size' => 'thumbnail', 'default_image' => false, 'order_of_image' => 1, 'link_to_post' => false, 'image_url' => false, 'image_class' => false, 'image_scan' => true, 'width' => false, 'height' => false, 'format' => 'img', 'echo' => true, 'lightbox' => false ); $args = apply_filters( 'get_the_image_args', $args ); $args = wp_parse_args( $args, $defaults ); extract( $args ); /* If a custom field key (array) is defined, check for images by custom field. */ if ( $custom_key ) $image = image_by_custom_field( $args ); /* If no image found and $the_post_thumbnail is set to true, check for a post image (WP feature). */ if ( !$image && $the_post_thumbnail ) $image = image_by_the_post_thumbnail( $args ); /* If no image found and $attachment is set to true, check for an image by attachment. */ if ( !$image && $attachment ) $image = image_by_attachment( $args ); /* If no image found and $image_scan is set to true, scan the post for images. */ if ( !$image && $image_scan ) $image = image_by_scan( $args ); /* If no image found and a $default_image is set, get the default image. */ if ( !$image && $default_image ) $image = image_by_default( $args ); /* If an image is returned, run it through the display function. */ if ( $image ) $image = display_the_image( $args, $image ); /* Allow plugins/theme to override the final output. */ $image = apply_filters( 'get_the_image', $image ); /* Display the image if $echo is set to true and the $format isn't an array. Else, return the image. */ if ( $echo && 'array' !== $format ) echo $image; else return $image; } function image_by_custom_field( $args = array() ) { /* If $custom_key is a string, we want to split it by spaces into an array. */ if ( !is_array( $args['custom_key'] ) ) $args['custom_key'] = preg_split( '#\s+#', $args['custom_key'] ); /* If $custom_key is set, loop through each custom field key, searching for values. */ if ( isset( $args['custom_key'] ) ) { foreach ( $args['custom_key'] as $custom ) { $image = get_metadata( 'post', $args['post_id'], $custom, true ); if ( $image ) break; } } /* If a custom key value has been given for one of the keys, return the image URL. */ if ( $image ) return array( 'url' => $image ); return false; } function image_by_the_post_thumbnail( $args = array() ) { /* Check for a post image ID (set by WP as a custom field). */ $post_thumbnail_id = get_post_thumbnail_id( $args['post_id'] ); /* If no post image ID is found, return false. */ if ( empty( $post_thumbnail_id ) ) return false; /* Apply filters on post_thumbnail_size because this is a default WP filter used with its image feature. */ $size = apply_filters( 'post_thumbnail_size', $args['default_size'] ); /* Get the attachment image source. This should return an array. */ $image = wp_get_attachment_image_src( $post_thumbnail_id, $size ); /* Return both the image URL and the post thumbnail ID. */ return array( 'url' => $image[0], 'post_thumbnail_id' => $post_thumbnail_id ); } function image_by_attachment( $args = array() ) { /* Get attachments for the inputted $post_id. */ $attachments = get_children( array( 'post_parent' => $args['post_id'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ); /* If no attachments are found, return false. */ if ( empty( $attachments ) ) return false; /* Loop through each attachment. Once the $order_of_image (default is '1') is reached, break the loop. */ foreach ( $attachments as $id => $attachment ) { if ( ++$i == $args['order_of_image'] ) { $image = wp_get_attachment_image_src( $id, $args['default_size'] ); break; } } /* Return the image URL. */ return array( 'url' => $image[0] ); } function image_by_scan( $args = array() ) { /* Search the post's content for the tag and get its URL. */ preg_match_all( '||i', get_post_field( 'post_content', $args['post_id'] ), $matches ); /* If there is a match for the image, return its URL. */ if ( isset( $matches ) && $matches[1][0] ) return array( 'url' => $matches[1][0] ); return false; } function image_by_default( $args = array() ) { return array( 'url' => $args['default_image'] ); } function display_the_image( $args = array(), $image = false ) { /* If there is no image URL, return false. */ if ( empty( $image['url'] ) ) return false; /* Extract the arguments for easy-to-use variables. */ extract( $args ); /* If there is a width or height, set them as HMTL-ready attributes. */ if ( $width ) $width = $width ; if ( $height ) $height = $height ; /* Loop through the custom field keys and add them as classes. */ if ( is_array( $custom_key ) ) { foreach ( $custom_key as $key ) $classes[] = str_replace( ' ', '-', strtolower( $key ) ); } /* Add the $default_size and any user-added $image_class to the class. */ $classes[] = $default_size; $classes[] = $image_class; /* Join all the classes into a single string. */ $class = join( ' ', $classes ); /* If $format should be an array, return the attributes in array format. */ if ( 'array' == $format ) return array( 'url' => $image['url'], 'alt' => esc_attr( strip_tags( get_post_field( 'post_title', $post_id ) ) ), 'class' => $class, 'link' => get_permalink( $post_id ) ); /* Add the image attributes to the element. */ $html = '' . esc_attr( strip_tags( get_post_field( 'post_title', $post_id ) ) ) . ''; /* If $link_to_post is set to true, link the image to its post. */ if ( $link_to_post ) $html = '' . $html . ''; /* If image_url is set to true display only url */ if ( $image_url ) $html = $image['url']; /* If lightbox is set to true display lightbox */ if ( $lightbox ) $html = '' . esc_attr( strip_tags( get_post_field( 'post_title', $post_id ) ) ) . ''; /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */ if ( $image['post_thumbnail_id'] ) do_action( 'end_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $default_size ); return $html; } //deactivate WordPress function remove_shortcode('gallery', 'gallery_shortcode'); //activate new function add_shortcode('gallery', 'dd_gallery_shortcode'); /** * The Gallery shortcode. * * This implements the functionality of the Gallery Shortcode for displaying * WordPress images on a post. * * @since 2.5.0 * * @param array $attr Attributes attributed to the shortcode. * @return string HTML content to display gallery. */ //the new renamed function function dd_gallery_shortcode($attr) { global $post, $wp_locale; static $instance = 0; $instance++; // Allow plugins/themes to override the default gallery template. $output = apply_filters('post_gallery', '', $attr); if ( $output != '' ) return $output; // 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 ID', 'id' => $post->ID, 'itemtag' => 'dl', 'rel' => 'prettyPhoto[gallery1]', // !!! Add attribute 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', 'exclude' => '' ), $attr)); $id = intval($id); if ( 'RAND' == $order ) $orderby = 'none'; if ( !empty($include) ) { $include = preg_replace( '/[^0-9,]+/', '', $include ); $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); $attachments = array(); foreach ( $_attachments as $key => $val ) { $attachments[$val->ID] = $_attachments[$key]; } } elseif ( !empty($exclude) ) { $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); } else { $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); } if ( empty($attachments) ) return ''; if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $att_id => $attachment ) $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; return $output; } $itemtag = tag_escape($itemtag); $captiontag = tag_escape($captiontag); $columns = intval($columns); $itemwidth = $columns > 0 ? floor(100/$columns) : 100; $float = $wp_locale->text_direction == 'rtl' ? 'right' : 'left'; $selector = "gallery-{$instance}"; $output = apply_filters('gallery_style', " \n"; return $output;} ?>