Created
February 28, 2013 17:15
-
-
Save lschatzkin/5058345 to your computer and use it in GitHub Desktop.
custom gallery shortcode for WordPress
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
function parse_gallery_shortcode($atts) { | |
global $post; | |
$output = apply_filters('post_gallery','', $atts); | |
extract(shortcode_atts(array( | |
'orderby' => 'menu_order ASC, ID ASC', | |
'id' => $post->ID, | |
'itemtag' => 'dl', | |
'icontag' => 'dt', | |
'captiontag' => 'dd', | |
'columns' => 10, | |
'size' => 'property-thumb', | |
'link' => 'file', | |
'ids' => array() | |
), $atts)); | |
$args = array( | |
'post_type' => 'attachment', | |
'posts_per_page' => 10, | |
'orderby' => $orderby | |
); | |
$images = get_posts($args); | |
echo '<div id="gallery-1" class="custom-gallery">'; | |
foreach ( $images as $image ) { | |
$caption = $image->post_excerpt; | |
$description = $image->post_content; | |
$title = $image->post_title; | |
$pname = $image->post_name; | |
$large_img = post_permalink() . $pname . '/'; | |
if($description == '') $description = $title; | |
$image_alt = get_post_meta($image->ID,'_wp_attachment_image_alt', true); | |
$img = wp_get_attachment_image_src($image->ID, $size); | |
// render gallery here | |
echo '<dl class="gallery-item">'; | |
echo '<dt class="gallery-icon">'; | |
echo '<a title="' . $title . '" href="' . $large_img . '"><img src="' . $img[0] . '" width="' . $img[1] . '" height="' . $img[2] . '"></a>'; | |
echo '</dt>'; | |
echo '</dl>'; | |
} | |
echo '</div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment