Guest User

Untitled

a guest
Oct 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. <?php
  2. /**
  3. * The Better Gallery shortcode, courtesy of WordPress Core
  4. *
  5. * Wanted to extend our Bootstrap Slideshow so that you could put in Post IDs and get back a slideshow.
  6. * Basically the same thing that the default slideshow does, so why not use that!
  7. *
  8. * @since 1.0
  9. *
  10. * @param array $attr Attributes of the shortcode.
  11. * @return string HTML content to display gallery.
  12. */
  13. function make_new_gallery_shortcode($attr) {
  14. $post = get_post();
  15.  
  16. static $instance = 0;
  17. $instance++;
  18.  
  19. if ( ! empty( $attr['ids'] ) ) {
  20. // 'ids' is explicitly ordered, unless you specify otherwise.
  21. if ( empty( $attr['orderby'] ) )
  22. $attr['orderby'] = 'post__in';
  23. $attr['include'] = $attr['ids'];
  24. }
  25.  
  26. // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
  27. if ( isset( $attr['orderby'] ) ) {
  28. $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
  29. if ( !$attr['orderby'] )
  30. unset( $attr['orderby'] );
  31. }
  32.  
  33. extract(shortcode_atts(array(
  34. 'order' => 'ASC',
  35. 'orderby' => 'menu_order ID',
  36. 'id' => $post->ID,
  37. 'itemtag' => 'dl',
  38. 'icontag' => 'dt',
  39. 'captiontag' => 'dd',
  40. 'columns' => 3,
  41. 'size' => 'thumbnail',
  42. 'include' => '',
  43. 'exclude' => ''
  44. ), $attr));
  45.  
  46.  
  47. $rand = mt_rand( 0, $id );
  48.  
  49. $id = intval($id);
  50. if ( 'RAND' == $order )
  51. $orderby = 'none';
  52.  
  53. if ( !empty($include) ) {
  54. $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  55.  
  56. $attachments = array();
  57. foreach ( $_attachments as $key => $val ) {
  58. $attachments[$val->ID] = $_attachments[$key];
  59. }
  60. } elseif ( !empty($exclude) ) {
  61. $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  62. } else {
  63. $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  64. }
  65.  
  66. if ( empty($attachments) )
  67. return '';
  68.  
  69. $output = '<div id="myCarousel-' . $rand . '" class="carousel slide" data-interval=""><div class="carousel-inner">';
  70.  
  71. $i = 0;
  72. foreach( $attachments as $id => $attachment ) {
  73. $i++;
  74. if ($i == 1) {
  75. $output .= '<div class="item active">';
  76. } else {
  77. $output .= '<div class="item">';
  78. }
  79. $output .= wp_get_attachment_link( $attachment->ID, 'medium');
  80. if (isset($attachment->post_title)) {
  81. $output .= '<div class="carousel-caption">';
  82. $output .= '<h4>' . $attachment->post_title . '</h4>';
  83. if (isset($attachment->post_excerpt)) {
  84. $output .= Markdown( $attachment->post_excerpt );
  85. }
  86. $output .= '</div>';
  87.  
  88. }
  89. $output .= '</div>';
  90.  
  91. } //foreach
  92. $output .= '</div>
  93. <a class="left carousel-control" href="#myCarousel-' . $rand . '" data-slide="prev">‹</a>
  94. <a class="right carousel-control" href="#myCarousel-' . $rand . '" data-slide="next">›</a>
  95. </div>';
  96. $output .= '<p class="pull-right"><span class="label viewall" style="cursor:pointer">View All</span></p>';
  97. $output .= '
  98. <script>
  99. jQuery(document).ready(function(){
  100. jQuery(".viewall").click(function() {
  101. jQuery(".carousel-inner").removeClass("carousel-inner");
  102. googletag.pubads().refresh();
  103. _gaq.push([\'_trackPageview\']);
  104. urlref = location.href;
  105. PARSELY.beacon.trackPageView({
  106. url: urlref,
  107. urlref: urlref,
  108. js: 1,
  109. action_name: "Next Slide"
  110. });
  111. jQuery(this).addClass(\'hide\');
  112. return true;
  113. })
  114. });
  115. </script>
  116. ';
  117. $output .= '<div class="clearfix"></div>';
  118. return $output;
  119. }
  120.  
  121. add_shortcode( 'new_gallery', 'make_new_gallery_shortcode' );
Add Comment
Please, Sign In to add comment