Hello David,
Thanks for writing in!
Because what you are trying to accomplish requires a template customization, we would highly to suggest that you use a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.
After the child theme is set up, please add the following code in your child theme’s functions.php file
// Custom featured image
// =============================================================================
function x_featured_image( $cropped = '' ) {
$stack = x_get_stack();
$fullwidth = ( in_array( 'x-full-width-active', get_body_class() ) ) ? true : false;
if ( has_post_thumbnail() ) {
if ( $cropped == 'cropped' ) {
if ( $fullwidth ) {
$thumb = get_the_post_thumbnail( NULL, 'entry-cropped-fullwidth', NULL );
} else {
$thumb = get_the_post_thumbnail( NULL, 'entry-cropped', NULL );
}
} else {
if ( $fullwidth ) {
$thumb = get_the_post_thumbnail( NULL, 'entry-fullwidth', NULL );
} else {
$thumb = get_the_post_thumbnail( NULL, 'entry', NULL );
}
}
switch ( is_singular() ) {
case true:
printf( '<div class="entry-thumb">%s</div>', $thumb );
break;
case false:
printf( '<a href="%1$s" class="entry-thumb" title="%2$s">%3$s</a>',
esc_url( get_permalink() ),
esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ),
$thumb
);
break;
}
} else {
global $post, $posts;
$thumb = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$thumb = $matches [1] [0];
$image = '<img src="' . $thumb . '" class="attachment wp-post-image" alt="">';
if ( is_archive() ) {
printf( '<a href="%1$s" class="entry-thumb" title="%2$s">%3$s</a>',
esc_url( get_permalink() ),
esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ),
$image
);
}
}
}
// =============================================================================
The code above will display the featured image when there is assigned in the post and if none, it will check the post content, look for the first image and will display it as the featured image.
We would loved to know if this has work for you. Thank you.