Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2011
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. function tt_gallery_shortcode($attr)
  2. {
  3. global $post;
  4.  
  5. static $instance = 0;
  6. $instance++;
  7.  
  8. // Allow plugins/themes to override the default gallery template.
  9. $output = apply_filters('post_gallery', '', $attr);
  10. if ( $output != '' )
  11. return $output;
  12.  
  13. // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
  14. if ( isset( $attr['orderby'] ) ) {
  15. $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
  16. if ( !$attr['orderby'] )
  17. unset( $attr['orderby'] );
  18. }
  19.  
  20. extract(shortcode_atts(array(
  21. 'order' => 'ASC',
  22. 'orderby' => 'menu_order ID',
  23. 'id' => $post->ID,
  24. 'itemtag' => 'li',
  25. 'icontag' => 'span',
  26. 'captiontag' => 'div',
  27. 'columns' => 0,
  28. 'size' => 'thumbnail'
  29. ), $attr));
  30.  
  31. $id = intval($id);
  32. $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  33.  
  34. if ( empty($attachments) )
  35. return '';
  36.  
  37. if ( is_feed() ) {
  38. $output = "\n";
  39. foreach ( $attachments as $att_id => $attachment )
  40. $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
  41. return $output;
  42. }
  43.  
  44. $itemtag = tag_escape($itemtag);
  45. $captiontag = tag_escape($captiontag);
  46. $columns = intval($columns);
  47. $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
  48.  
  49. $selector = "gallery-{$instance}";
  50.  
  51. $output = apply_filters('gallery_style', "
  52. <ul class='thumbs noscript'>
  53. ");
  54.  
  55. $i = 0;
  56. foreach ( $attachments as $id => $attachment ) {
  57.  
  58. $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, false, false);
  59. $link = str_replace('<a href=', "<a class='thumb' href=", $link);
  60.  
  61. $link_title = "<{$captiontag} class='caption'> <div class='image-title'>" . wptexturize($attachment->post_title) . "</div>";
  62.  
  63. $link_caption = "<div class='image-excerpt'>" . wptexturize($attachment->post_excerpt) . "</div>";
  64.  
  65. $link_description = "<div class='image-description'>" . wptexturize($attachment->post_content) . "</div> </{$captiontag}>";
  66.  
  67. $output .= "<{$itemtag}>
  68. ";
  69. $output .= "$link
  70. ";
  71. $output .= "$link_title
  72. ";
  73. $output .= "$link_caption
  74. ";
  75. $output .= "$link_description
  76. ";
  77. $output .= "</{$itemtag}>
  78. ";
  79.  
  80. if ( $columns > 0 && ++$i % $columns == 0 )
  81. $output .= '';
  82. }
  83.  
  84. $output .= "
  85. </ul>\n";
  86.  
  87. return $output;
  88. }
  89.  
  90. add_shortcode('gallery', 'tt_gallery_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement