Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Post Thumbnails
- add_theme_support( 'post-thumbnails' );
- set_post_thumbnail_size( 210, 102, true );
- add_image_size( 'gallery-size', 680, 380, true );
- // Custom Gallery shortcode
- add_shortcode('gallery_home', 'homepg_gallery_shortcode');
- function homepg_gallery_shortcode($attr) {
- global $post;
- static $instance = 0;
- $instance++;
- // 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',
- 'icontag' => 'dt',
- 'captiontag' => 'dd',
- 'columns' => 3,
- 'size' => 'gallery-size',
- '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 = "";
- foreach ( $attachments as $att_id => $attachment )
- $output .= wp_get_attachment_link($att_id, $size, true) . "";
- return $output;
- }
- // check to see if tags have been set to false. If they are the defaults or have been set to a string value use that as the tag.
- if ($itemtag) $itemtag = tag_escape($itemtag);
- if ($captiontag) $captiontag = tag_escape($captiontag);
- if ($icontag) $icontag = tag_escape($icontag);
- $columns = intval($columns);
- $selector = "gallery-{$instance}";
- $output = "";
- $i = 0;
- foreach ( $attachments as $id => $attachment ) {
- ++$i;
- $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_image($id, $size, false) : wp_get_attachment_image($id, $size, false);
- if ($itemtag) {
- $output .= '';
- if( $columns > 0 && $i % $columns == 0 ) $output .= "";
- $output .= '';
- }
- if ($icontag) $output .= "";
- $output .= "".$link;
- if ($icontag) $output .= "";
- // if the attachment has a caption set
- if ( trim($attachment->post_excerpt) ) {
- if ($captiontag) $output .= "";
- $output .= wptexturize($attachment->post_excerpt);
- if ($captiontag) $output .= "";
- }
- if ($itemtag) $output .= "";
- if ( $columns > 0 && $i % $columns == 0 ) $output .= "";
- }
- $output .= "";
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement