Skip to content

Instantly share code, notes, and snippets.

@ChrisFlannagan
Last active June 2, 2016 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisFlannagan/82e07143624446c3cdccd29eb8bfa1ba to your computer and use it in GitHub Desktop.
Save ChrisFlannagan/82e07143624446c3cdccd29eb8bfa1ba to your computer and use it in GitHub Desktop.
<div u="slides" style="cursor: move; position: absolute; overflow: hidden; left: 0px; top: 0px; width: 1090px; height: 550px;">
<?php
$slides_trans = get_transient( "slides_rest_api");
$allslides = array();
if( !$slides_trans || $_REQUEST['reset_trans'] == 'please' ) {
// Best to use wp_remote_get here but for brevity in example we use file_get_contents
$callret = file_get_contents( site_url() . '/wp-json/posts?filter[category_name]=home-slides&filter[posts_per_page]=-1' );
$allslides = json_decode( $callret, true );
set_transient( "slides_rest_api", $callret, 60*60*12 );
} else {
$allslides = json_decode( $slides_trans, true );
}
$cnt = 0;
foreach ($allslides as $slide) {
$thumbnail_id = get_post_thumbnail_id($slide['ID']);
$thumbnail = wp_get_attachment_image_src($thumbnail_id, 'large');
?>
<div data-idle="6500">
<a href="<?php echo esc_url( $slide['link'] ); ?>"><img u="image" src='<?php echo $thumbnail[0]; ?>' /></a>
</div>
<?php
$cnt++;
}
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment