Skip to content

Instantly share code, notes, and snippets.

@f1code
Last active January 24, 2016 21:44
Show Gist options
  • Select an option

  • Save f1code/1026ba0468b8d1c5adce to your computer and use it in GitHub Desktop.

Select an option

Save f1code/1026ba0468b8d1c5adce to your computer and use it in GitHub Desktop.
Responsive thumbnail gallery using the Wordpress API
// customize to add the thumbnail to the returned data
add_filter( 'rest_prepare_event', function($data, $post, $request) {
$_data = $data->data;
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumbnail = wp_get_attachment_image_src( $thumbnail_id );
$_data['featured_image_thumbnail_url'] = $thumbnail[0];
$data->data = $_data;
return $data;
}, 10, 3 );
// allow filtering by meta fields
add_filter('query_vars', function($qv) {
$qv[] = 'meta_key';
$qv[] = 'meta_value';
$qv[] = 'meta_compare';
return $qv;
});
<style>
.image-container {
width: 100%;
position: relative;
}
figure {
}
figure img {
width: 100%;
/*height: calc(100% - 20px);*/
}
figure figcaption {
width: 100%;
position: absolute;
bottom: 0;
left: 0;
height: 20px;
background-color: white;
opacity: 0;
transition: opacity 1s;
}
figure:hover figcaption {
opacity: 0.8;
}
</style>
<div class="image-container" style="width: 100%; height: 2000px">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment