Skip to content

Commit 141958b

Browse files
committed
Merge branch 'ottadvantage-master'
2 parents adbb008 + 464079c commit 141958b

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

include/lcp-catlist.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,16 @@ private function lcp_trim_excerpt($text = ''){
407407
}
408408

409409
public function get_thumbnail($single, $lcp_thumb_class = null){
410+
if ($this->utils->lcp_not_empty('force_thumbnail')){
411+
$force_thumbnail = $this->params['force_thumbnail'];
412+
} else {
413+
$force_thumbnail = 'no';
414+
}
410415
return LcpThumbnail::get_instance()->get_thumbnail(
411416
$single,
412417
$this->params['thumbnail'],
413418
$this->params['thumbnail_size'],
419+
$force_thumbnail,
414420
$lcp_thumb_class);
415421
}
416422

include/lcp-thumbnail.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
class LcpThumbnail{
3-
43
// Singleton implementation
54
private static $instance = null;
65

@@ -11,13 +10,13 @@ public static function get_instance(){
1110
return self::$instance;
1211
}
1312

14-
/**
13+
/**
1514
* Get the post Thumbnail
1615
* @see http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
1716
* @param unknown_type $single
1817
*
1918
*/
20-
public function get_thumbnail($single, $thumbnail, $thumbnail_size, $lcp_thumb_class = null){
19+
public function get_thumbnail($single, $thumbnail, $thumbnail_size, $force_thumbnail, $lcp_thumb_class = null){
2120
$lcp_thumbnail = null;
2221

2322
if( $thumbnail == 'yes' ){
@@ -40,14 +39,29 @@ public function get_thumbnail($single, $thumbnail, $thumbnail_size, $lcp_thumb_c
4039
}
4140

4241
$lcp_thumbnail = '<a href="' . esc_url(get_permalink($single->ID)) .
43-
'" title="' . esc_attr($single->post_title) . '">';
42+
'" title="' . esc_attr($single->post_title) . '">';
4443

4544
$lcp_thumbnail .= get_the_post_thumbnail(
4645
$single->ID,
4746
$lcp_thumb_size,
4847
( $lcp_thumb_class != null ) ? array( 'class' => $lcp_thumb_class ) : null
4948
);
5049
$lcp_thumbnail .= '</a>';
50+
} else {
51+
// if thumbnail is requested but not found as featured image, grab first image in the content of the post
52+
if ( ($force_thumbnail === 'yes'|| $force_thumbnail === 'true') && preg_match('~<img[^>]*src\s?=\s?[\'"]([^\'"]*)~i',get_the_content(), $imgMatches)) {
53+
$lcp_thumbnail = '<a href="' . esc_url(get_permalink($single->ID)) .
54+
'" title="' . esc_attr($single->post_title) . '">';
55+
56+
$lcp_thumbnail .= '<img src="' . esc_url($imgMatches[1]) . '" ';
57+
if ( $lcp_thumb_class != null ) { // thumbnail class passed as parameter to shortcode
58+
$lcp_thumbnail .= 'class="' . $lcp_thumb_class . '" ';
59+
}
60+
else { // Otherwise, use this class name
61+
$lcp_thumbnail .= 'class="lcp_thumbnail" ';
62+
}
63+
$lcp_thumbnail .= ' /></a>';
64+
}
5165
}
5266
} else {
5367
# Check for a YouTube video thumbnail
@@ -68,21 +82,20 @@ private function check_youtube_thumbnail($content){
6882
preg_match($yt_pattern, $content, $matches) ||
6983
preg_match($yt_vpattern, $content, $matches) ||
7084
preg_match($yt_epattern, $content, $matches)
71-
){
72-
$youtubeurl = $matches[0];
85+
) {
86+
$youtubeurl = $matches[0];
7387

74-
if ($youtubeurl):
75-
$imageurl = "http://i.ytimg.com/vi/{$matches[3]}/1.jpg";
76-
endif;
88+
if ($youtubeurl){
89+
$imageurl = "http://i.ytimg.com/vi/{$matches[3]}/1.jpg";
90+
}
7791

78-
$lcp_ytimage = '<img src="' . $imageurl . '" alt="' . $single->post_title . '" />';
92+
$lcp_ytimage = '<img src="' . $imageurl . '" alt="' . $single->post_title . '" />';
7993

80-
if ($lcp_thumb_class != null):
81-
$thmbn_class = ' class="' . $lcp_thumb_class . '" />';
94+
if ($lcp_thumb_class != null){
95+
$thmbn_class = ' class="' . $lcp_thumb_class . '" />';
8296
$lcp_ytimage = preg_replace("/\>/", $thmbn_class, $lcp_ytimage);
83-
endif;
84-
85-
$lcp_thumbnail .= '<a href="' . get_permalink($single->ID).'">' . $lcp_ytimage . '</a>';
97+
}
98+
$lcp_thumbnail .= '<a href="' . get_permalink($single->ID).'">' . $lcp_ytimage . '</a>';
8699
}
87100
}
88101
}

list-category-posts.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static function catlist_func($atts, $content = null) {
8787
'thumbnail' => 'no',
8888
'thumbnail_size' => 'thumbnail',
8989
'thumbnail_class' => '',
90+
'force_thumbnail' => '',
9091
'title_tag' => '',
9192
'title_class' => '',
9293
'title_limit' => '0',

readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ Show the full content of the post regardless of whether there is a &lt;!--more--
313313

314314
* **thumbnail** - Show post thumbnail (http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/). Default is 'no'. Ex: `[catlist thumbnail=yes]`.
315315

316+
* **force_thumbnail** - If the previous parameter is set to 'yes', and there's no featured image, setting this to 'yes' or 'true' will make the plugin look for the first image in the post and use it as a thumbnail. Ex: `[catlist thumbnail=yes force_thumbnail=yes]`.
317+
316318
* **thumbnail_size** - Either a string keyword (thumbnail, medium, large or full) or 2 values representing width and height in pixels. Ex: `[catlist thumbnail_size=32,32]` or `[catlist thumbnail_size=thumbnail]`
317319

318320
* **thumbnail_class** - Set a CSS class for the thumbnail.
@@ -533,6 +535,7 @@ Template system has changed. Custom templates should be stored in WordPress them
533535
= 0.67 =
534536
* Adds custom css class to current page in pagination `lcp_currentpage`.
535537
* Adds child_categories parameter to being able to exclude child categories' posts from a list.
538+
* New feature to look for the first image in a post when requesting a thumbnail and the post has no featured image. Thanks Michael J. Gibbs for writing this code :)
536539

537540
= 0.66 =
538541
* Full release notes: https://github.com/picandocodigo/List-Category-Posts/releases/tag/0.66

0 commit comments

Comments
 (0)