Skip to content

Commit 0527bd1

Browse files
committed
Merge branch 'master' of https://github.com/ottadvantage/List-Category-Posts into ottadvantage-master
2 parents adbb008 + 581bdd0 commit 0527bd1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

include/lcp-thumbnail.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ public function get_thumbnail($single, $thumbnail, $thumbnail_size, $lcp_thumb_c
4949
);
5050
$lcp_thumbnail .= '</a>';
5151
}
52+
else { // if thumbnail is requested but not found as featured image, grab first image in the content of the
53+
if (preg_match('~<img[^>]*src\s?=\s?[\'"]([^\'"]*)~i',get_the_content(), $imgMatches)) {
54+
$lcp_thumbnail = '<a href="' . esc_url(get_permalink($single->ID)) .
55+
'" title="' . esc_attr($single->post_title) . '">';
56+
57+
$lcp_thumbnail .= '<img src="' . esc_url($imgMatches[1]) . '" ';
58+
if ( $lcp_thumb_class != null ) { // thumbnail class passed as parameter to shortcode
59+
$lcp_thumbnail .= 'class="' . $lcp_thumb_class . '" ';
60+
}
61+
else { // Otherwise, use this class name
62+
$lcp_thumbnail .= 'class="lcp_thumbnail" ';
63+
}
64+
$lcp_thumbnail .= ' /></a>';
65+
}
66+
}
5267
} else {
5368
# Check for a YouTube video thumbnail
5469
$lcp_thumbnail = $this->check_youtube_thumbnail($single->content);

0 commit comments

Comments
 (0)