Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. add_shortcode('custom_gallery', 'custom_gallery_fn');
  2. function custom_gallery_fn($attr)
  3. {
  4. global $post;
  5. global $linker_sluger;
  6.  
  7. if (isset($attr['orderby'])) {
  8. $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
  9. if (!$attr['orderby'])
  10. unset($attr['orderby']);
  11. }
  12.  
  13. extract(shortcode_atts(array(
  14. 'order' => 'DESC',
  15. 'orderby' => 'menu_order ID',
  16. 'id' => $post->ID,
  17. 'itemtag' => 'dl',
  18. 'icontag' => 'dt',
  19. 'captiontag' => 'dd',
  20. 'columns' => 3,
  21. 'size' => 'large',
  22. 'ids' => '',
  23. 'exclude' => ''
  24. ), $attr));
  25.  
  26. $id = intval($id);
  27. if ('RAND' == $order) $orderby = 'none';
  28. if (!empty($ids)) {
  29. $ids = preg_replace('/[^0-9,]+/', '', $ids);
  30. $_attachments = get_posts(array(
  31. 'include' => $ids,
  32. 'post_status' => 'inherit',
  33. 'post_type' => 'attachment',
  34. 'post_mime_type' => 'image',
  35. 'order' => 'menu_order ID',
  36. 'orderby' => 'post__in',
  37. )
  38. );
  39.  
  40. $attachments = array();
  41. foreach ($_attachments as $key => $val) {
  42. $attachments[$val->ID] = $_attachments[$key];
  43. }
  44. }
  45.  
  46. if (empty($attachments)) return '';
  47.  
  48. if (is_page(16)) {
  49.  
  50. // Here's your actual output, you may customize it to your need
  51. $output = '<div class="single-album col-md-12 col-12">';
  52.  
  53. // Now you loop through each attachment
  54. $i = 0;
  55. foreach ($attachments as $id => $attachment) {
  56.  
  57.  
  58. $i++;
  59. // Fetch the thumbnail (or full image, it's up to you)
  60. // $img = wp_get_attachment_image_src($id, 'medium');
  61. // $img = wp_get_attachment_image_src($id, 'my-custom-image-size');
  62. $img = wp_get_attachment_image_src($id, 'full');
  63. //print_r($img);
  64.  
  65. $output .= "<div class=\"single-gallery-image\">";
  66. $output .= "<img src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"\" />\n";
  67. $output .= "</div>";
  68.  
  69. if($i==1){
  70. break;
  71. }
  72. }
  73. //$output .= "</div>\n";
  74.  
  75. $output .= "</div>";
  76.  
  77. }
  78. else {
  79. // Here's your actual output, you may customize it to your need
  80. $output = '<div class="gallery-investition-single col-md-12 col-12">
  81. <div class="row">';
  82. // Now you loop through each attachment
  83. foreach ($attachments as $id => $attachment) {
  84. // Fetch the thumbnail (or full image, it's up to you)
  85. // $img = wp_get_attachment_image_src($id, 'medium');
  86. // $img = wp_get_attachment_image_src($id, 'my-custom-image-size');
  87. $img = wp_get_attachment_image_src($id, 'full');
  88. $output .= "<a href=\"{$img[0]}\" class=\"foobox col-md-4 col-12\" rel=\"gallery\">";
  89. $output .= "<div class=\"single-gallery-image\">";
  90. $output .= "<img src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"\" />\n";
  91. $output .= "</div>";
  92. $output .= "</a>";
  93. }
  94. //$output .= "</div>\n";
  95. $output .= "</div>";
  96. $output .= "</div>";
  97.  
  98. }
  99.  
  100.  
  101. return $output;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement