To display featured images of Posts linking to their permalinks my go-to code (inside a function hooked to an action in theme template files like home.php or in functions.php) is
if ( $image = genesis_get_image( 'format=url&size=posts-page-thumbnail' ) ) { | |
printf( '<div class="posts-page-thumbnail"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), $image, the_title_attribute( 'echo=0' ) ); | |
} |
where posts-page-thumbnail
is the image size handle registered in functions.php via
// Register a custom image size for images on the Posts page | |
add_image_size( 'posts-page-thumbnail', 600, 400, true ); |
genesis_get_image() and genesis_image() functions fetch/display featured images if present. If featured image is not present, they will show the first image attached to the entry.
Attached image: Any image that has been uploaded from with in a specific Post.
What if a Post does not have a featured image or at least one attached image but instead has at least one image embedded or inserted (or attached to another entry) whether it be internal or external?
<img src="http://genesis-blank.dev/wp-content/uploads/2013/06/wordpress.png" alt="Heres a sample caption, with a sample image aligned left." width="142" height="142" /> |
genesis_get_image() and genesis_image() in this case will have empty output.
Justin Tadlock’s Get the Image plugin can be used in situations like this when you want the embedded image to be pulled and shown.
get_the_image( array( 'size' => 'posts-page-thumbnail', 'scan' => true ) ); |
For some context, you may want to visit this discussion on Genesis Facebook group. I have also provided a full working sample code over there for displaying posts on Posts page in a 3 column grid with the linked image (featured or attached or embedded – in that order), title below that and the date below that.