Skip to content

Instantly share code, notes, and snippets.

@apisandipas
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save apisandipas/6a2a292ba5e6eff1e955 to your computer and use it in GitHub Desktop.

Select an option

Save apisandipas/6a2a292ba5e6eff1e955 to your computer and use it in GitHub Desktop.
With Retina.js in the mix, retina images are picked up automagically.
<?php
$images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'post_mime_type' => 'image',
);
if ( $images ) : ?>
<?php foreach( $images as $image ) : ?>
<span data-picture>
<span data-src="<?php echo wp_get_attachment_image_src($image->ID, 'small'); ?>"></span>
<span data-src="<?php echo wp_get_attachment_image_src($image->ID, 'medium'); ?>" data-media="(min-width: 769px)"></span>
<span data-src="<?php echo wp_get_attachment_image_src($image->ID, 'large'); ?>" data-media="(min-width: 991px)"></span>
<noscript>
<img src="<?php echo wp_get_attachment_image_src($image->ID, 'medium'); ?>"/>
</noscript>
</span>
<?php endforeach; ?>
<php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment