Skip to content

Instantly share code, notes, and snippets.

@joshrainwater
Created August 18, 2014 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshrainwater/69b94e5169f7252bc1cd to your computer and use it in GitHub Desktop.
Save joshrainwater/69b94e5169f7252bc1cd to your computer and use it in GitHub Desktop.
Foundation Interchange + Wordpress Featured Images
<?php
function theme_support() {
add_theme_support('post-thumbnails');
// default thumb size
set_post_thumbnail_size(500, 320, true);
// Add thumbnail sizes for various screen sizes and locations
add_image_size('blog-feature-small', 1000, 600, true); // Featured Small
add_image_size('blog-feature-medium', 1500, 500, true); // Featured Medium
add_image_size('blog-feature-large', 2000, 600, true); // Featured Large
add_image_size('blog-thumbnail-small', 500, 320, true); // Image for small screens
add_image_size('blog-thumbnail-medium', 750, 350, true); // Image for medium up
}
add_action('after_setup_theme','theme_support', 16);
// Call get_custom_post_thumbnail($ID) to get blog images, or get_custom_post_thumbnail($ID, true) to get the larger featured image
function get_custom_post_thumbnail($postID, $featured=false) {
if($featured) {
$smallsrc = wp_get_attachment_image_src( get_post_thumbnail_id($postID), 'blog-feature-small' );
$mediumsrc = wp_get_attachment_image_src( get_post_thumbnail_id($postID), 'blog-feature-medium' );
$largesrc = wp_get_attachment_image_src( get_post_thumbnail_id($postID), 'blog-feature-large' );
} else {
$smallsrc = wp_get_attachment_image_src( get_post_thumbnail_id($postID), 'blog-thumbnail-small' );
$mediumsrc = wp_get_attachment_image_src( get_post_thumbnail_id($postID), 'blog-thumbnail-medium' );
$largesrc = wp_get_attachment_image_src( get_post_thumbnail_id($postID), 'blog-thumbnail-medium' );
}
?><img src="<?php echo $smallsrc[0]; ?>" data-interchange="[<?php echo $smallsrc[0]; ?>, (small)], [<?php echo $mediumsrc[0]; ?>, (medium)], [<?php echo $largesrc[0]; ?>, (large)]"><?php
}
?>
@joshrainwater
Copy link
Author

A quick function that is able to take a myriad featured and thumbnail post sizes and replace them with the proper Interchange format from Foundation.

Within a theme, the calls to the_post_thumbnail() would need to be replaced with get_custom_post_thumbnail($post->ID)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment