Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode('custom_gallery', 'custom_gallery_fn');
- function custom_gallery_fn($attr)
- {
- global $post;
- global $linker_sluger;
- if (isset($attr['orderby'])) {
- $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
- if (!$attr['orderby'])
- unset($attr['orderby']);
- }
- extract(shortcode_atts(array(
- 'order' => 'DESC',
- 'orderby' => 'menu_order ID',
- 'id' => $post->ID,
- 'itemtag' => 'dl',
- 'icontag' => 'dt',
- 'captiontag' => 'dd',
- 'columns' => 3,
- 'size' => 'large',
- 'ids' => '',
- 'exclude' => ''
- ), $attr));
- $id = intval($id);
- if ('RAND' == $order) $orderby = 'none';
- if (!empty($ids)) {
- $ids = preg_replace('/[^0-9,]+/', '', $ids);
- $_attachments = get_posts(array(
- 'include' => $ids,
- 'post_status' => 'inherit',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'order' => 'menu_order ID',
- 'orderby' => 'post__in',
- )
- );
- $attachments = array();
- foreach ($_attachments as $key => $val) {
- $attachments[$val->ID] = $_attachments[$key];
- }
- }
- if (empty($attachments)) return '';
- if (is_page(16)) {
- // Here's your actual output, you may customize it to your need
- $output = '<div class="single-album col-md-12 col-12">';
- // Now you loop through each attachment
- $i = 0;
- foreach ($attachments as $id => $attachment) {
- $i++;
- // Fetch the thumbnail (or full image, it's up to you)
- // $img = wp_get_attachment_image_src($id, 'medium');
- // $img = wp_get_attachment_image_src($id, 'my-custom-image-size');
- $img = wp_get_attachment_image_src($id, 'full');
- //print_r($img);
- $output .= "<div class=\"single-gallery-image\">";
- $output .= "<img src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"\" />\n";
- $output .= "</div>";
- if($i==1){
- break;
- }
- }
- //$output .= "</div>\n";
- $output .= "</div>";
- }
- else {
- // Here's your actual output, you may customize it to your need
- $output = '<div class="gallery-investition-single col-md-12 col-12">
- <div class="row">';
- // Now you loop through each attachment
- foreach ($attachments as $id => $attachment) {
- // Fetch the thumbnail (or full image, it's up to you)
- // $img = wp_get_attachment_image_src($id, 'medium');
- // $img = wp_get_attachment_image_src($id, 'my-custom-image-size');
- $img = wp_get_attachment_image_src($id, 'full');
- $output .= "<a href=\"{$img[0]}\" class=\"foobox col-md-4 col-12\" rel=\"gallery\">";
- $output .= "<div class=\"single-gallery-image\">";
- $output .= "<img src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"\" />\n";
- $output .= "</div>";
- $output .= "</a>";
- }
- //$output .= "</div>\n";
- $output .= "</div>";
- $output .= "</div>";
- }
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement