Last active
September 17, 2017 03:30
-
-
Save alandbh/ce4c371c32a6049c6825dde233118c19 to your computer and use it in GitHub Desktop.
Galeria wp 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ---------------- | |
It changes the output HTML of Wordpress default gallery | |
Originally implemented by t31os (Wordpress Stack Exchange) | |
Alan | |
----------------- */ | |
add_filter('post_gallery', 'my_post_gallery', 10, 2); | |
function my_post_gallery($output, $attr) { | |
global $post; | |
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' => 'thumbnail', | |
'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]; | |
} | |
} | |
if (empty($attachments)) return ''; | |
// Here's your actual output, you may customize it to your need | |
$output = "<div class=\"galeria-wrapper lightGallery post-image\">\n"; | |
//$output .= "<br><br><hr><h3>Galeria de fotos</h3>\n"; | |
//$output .= "<ul data-orbit class=\"lightGallery\">\n"; | |
// 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'); | |
$imagemMenor = wp_get_attachment_image( $id, array('150', '150')); | |
$img = wp_get_attachment_image_src($id, 'large'); | |
//$the_caption = get_post_field('post_content', $id); | |
$the_caption = $attachment->post_excerpt; | |
$the_description = $attachment->post_content; | |
// $output .= '<pre>'; | |
// $output .= var_dump($attachment); | |
// $output .= '</pre>'; | |
$output .= "<a href=\"{$img[0]}\" data-src=\"{$img[0]}\" title=\"{$the_caption}\">\n"; | |
$output .= "$imagemMenor"; | |
$output .= "</a>\n"; | |
//$output .= "</li>\n"; | |
} | |
//$output .= "</ul>\n"; | |
$output .= "</div>\n"; | |
return $output; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment