Skip to content

Instantly share code, notes, and snippets.

@ckschmieder
Created October 6, 2016 15:42
Show Gist options
  • Save ckschmieder/b2e4d24dde376f5cf0e55e2aabb67367 to your computer and use it in GitHub Desktop.
Save ckschmieder/b2e4d24dde376f5cf0e55e2aabb67367 to your computer and use it in GitHub Desktop.
Need this to work with my custom image field in stead of the_post_thumbnail
<?php
global $post;
$parents = get_post_ancestors( $post->ID );
/* Get the ID of the 'top most' Page if not return current page ID */
$id = ($parents) ? $parents[count($parents)-1]: $post->ID;
$image = get_field('top_image');
if( $image( $id )) {
the_post_thumbnail( $id, 'thumbnail');
}
?>
<!-- This is how I currently display the custom image field -->
<?php
// get an image field
$image = get_field('top_image');
// each image contains a custom field called 'link'
$link = get_field('link', $image['ID']);
// render
?>
<figure class="featured-image">
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
</figure>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment