post_content, 'caption' ) ) {
// Find first image with a caption
$output_caption = preg_match_all('/\[caption(.)*caption="([\s\S][^"]*)"]
(]*>)<\/a>\[\/caption\]/im', $post->post_content, $caption_matches );
// [2] = first capturing group (information inside caption="")
// [3] = first image src
// second [0] = first iteration of each
if( !empty( $output_caption ) ) {
$first_caption = $caption_matches[2][0];
$first_img = $caption_matches[3][0];
echo '' . $first_img . '' . "\n" .
'' . esc_html( $first_caption ) . '
';
}
} else {
// Find first image with no caption
$first_img = '';
ob_start();
ob_end_clean();
$output_nocaption = preg_match_all('/()/i', $post->post_content, $matches );
$first_img = $matches[1][0];
// [0] = the first matching img src tag
// [1] = first capturing group in parenthesis (also represented by the entire img src tag)
if( empty( $first_img ) ) {
$first_img = '';
}
echo '' . $first_img . '';
}
} else { // If we are on a single page
the_content( sprintf(
/* translators: %s: Name of current post. */
__( 'Continue reading %s...', 'the-m-x' ),
the_title( '"', '"', false )
) );
wp_link_pages( array(
'before' => '' . esc_html__( 'Pages:', 'the-m-x' ),
'after' => '
',
) );
} ?>