List category posts - Version 0.67

Version Description

  • Adds custom css class to current page in pagination lcp_currentpage.
  • Adds child_categories parameter to being able to exclude child categories' posts from a list.
  • 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 :)
Download this release

Release Info

Developer fernandobt
Plugin Icon 128x128 List category posts
Version 0.67
Comparing to
See all releases

Code changes from version 0.66 to 0.67

include/lcp-catlist.php CHANGED
@@ -117,6 +117,9 @@ class CatList{
117
  if ( is_array($this->lcp_category_id) ){
118
  return array('category__and' => $this->lcp_category_id);
119
  } else {
 
 
 
120
  return array('cat'=> $this->lcp_category_id);
121
  }
122
  }
@@ -404,10 +407,16 @@ class CatList{
404
  }
405
 
406
  public function get_thumbnail($single, $lcp_thumb_class = null){
 
 
 
 
 
407
  return LcpThumbnail::get_instance()->get_thumbnail(
408
  $single,
409
  $this->params['thumbnail'],
410
  $this->params['thumbnail_size'],
 
411
  $lcp_thumb_class);
412
  }
413
 
117
  if ( is_array($this->lcp_category_id) ){
118
  return array('category__and' => $this->lcp_category_id);
119
  } else {
120
+ if($this->utils->lcp_not_empty('child_categories') && ($this->params['child_categories'] == ('no' || 'false') )){
121
+ return array('category__in'=> $this->lcp_category_id);
122
+ }
123
  return array('cat'=> $this->lcp_category_id);
124
  }
125
  }
407
  }
408
 
409
  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
+ }
415
  return LcpThumbnail::get_instance()->get_thumbnail(
416
  $single,
417
  $this->params['thumbnail'],
418
  $this->params['thumbnail_size'],
419
+ $force_thumbnail,
420
  $lcp_thumb_class);
421
  }
422
 
include/lcp-catlistdisplayer.php CHANGED
@@ -199,7 +199,7 @@ class CatListDisplayer {
199
  $link = '';
200
 
201
  if ($page == $current_page){
202
- $link = "<li>$current_page</li>";
203
  } else {
204
  $request_uri = $_SERVER['REQUEST_URI'];
205
  $query = $_SERVER['QUERY_STRING'];
199
  $link = '';
200
 
201
  if ($page == $current_page){
202
+ $link = "<li class='lcp_currentpage'>$current_page</li>";
203
  } else {
204
  $request_uri = $_SERVER['REQUEST_URI'];
205
  $query = $_SERVER['QUERY_STRING'];
include/lcp-thumbnail.php CHANGED
@@ -1,6 +1,5 @@
1
  <?php
2
  class LcpThumbnail{
3
-
4
  // Singleton implementation
5
  private static $instance = null;
6
 
@@ -11,13 +10,13 @@ class LcpThumbnail{
11
  return self::$instance;
12
  }
13
 
14
- /**
15
  * Get the post Thumbnail
16
  * @see http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
17
  * @param unknown_type $single
18
  *
19
  */
20
- public function get_thumbnail($single, $thumbnail, $thumbnail_size, $lcp_thumb_class = null){
21
  $lcp_thumbnail = null;
22
 
23
  if( $thumbnail == 'yes' ){
@@ -40,7 +39,7 @@ class LcpThumbnail{
40
  }
41
 
42
  $lcp_thumbnail = '<a href="' . esc_url(get_permalink($single->ID)) .
43
- '" title="' . esc_attr($single->post_title) . '">';
44
 
45
  $lcp_thumbnail .= get_the_post_thumbnail(
46
  $single->ID,
@@ -48,6 +47,21 @@ class LcpThumbnail{
48
  ( $lcp_thumb_class != null ) ? array( 'class' => $lcp_thumb_class ) : null
49
  );
50
  $lcp_thumbnail .= '</a>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
52
  } else {
53
  # Check for a YouTube video thumbnail
@@ -68,21 +82,20 @@ class LcpThumbnail{
68
  preg_match($yt_pattern, $content, $matches) ||
69
  preg_match($yt_vpattern, $content, $matches) ||
70
  preg_match($yt_epattern, $content, $matches)
71
- ){
72
- $youtubeurl = $matches[0];
73
 
74
- if ($youtubeurl):
75
- $imageurl = "http://i.ytimg.com/vi/{$matches[3]}/1.jpg";
76
- endif;
77
 
78
- $lcp_ytimage = '<img src="' . $imageurl . '" alt="' . $single->post_title . '" />';
79
 
80
- if ($lcp_thumb_class != null):
81
- $thmbn_class = ' class="' . $lcp_thumb_class . '" />';
82
  $lcp_ytimage = preg_replace("/\>/", $thmbn_class, $lcp_ytimage);
83
- endif;
84
-
85
- $lcp_thumbnail .= '<a href="' . get_permalink($single->ID).'">' . $lcp_ytimage . '</a>';
86
  }
87
  }
88
  }
1
  <?php
2
  class LcpThumbnail{
 
3
  // Singleton implementation
4
  private static $instance = null;
5
 
10
  return self::$instance;
11
  }
12
 
13
+ /**
14
  * Get the post Thumbnail
15
  * @see http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
16
  * @param unknown_type $single
17
  *
18
  */
19
+ public function get_thumbnail($single, $thumbnail, $thumbnail_size, $force_thumbnail, $lcp_thumb_class = null){
20
  $lcp_thumbnail = null;
21
 
22
  if( $thumbnail == 'yes' ){
39
  }
40
 
41
  $lcp_thumbnail = '<a href="' . esc_url(get_permalink($single->ID)) .
42
+ '" title="' . esc_attr($single->post_title) . '">';
43
 
44
  $lcp_thumbnail .= get_the_post_thumbnail(
45
  $single->ID,
47
  ( $lcp_thumb_class != null ) ? array( 'class' => $lcp_thumb_class ) : null
48
  );
49
  $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
+ }
65
  }
66
  } else {
67
  # Check for a YouTube video thumbnail
82
  preg_match($yt_pattern, $content, $matches) ||
83
  preg_match($yt_vpattern, $content, $matches) ||
84
  preg_match($yt_epattern, $content, $matches)
85
+ ) {
86
+ $youtubeurl = $matches[0];
87
 
88
+ if ($youtubeurl){
89
+ $imageurl = "http://i.ytimg.com/vi/{$matches[3]}/1.jpg";
90
+ }
91
 
92
+ $lcp_ytimage = '<img src="' . $imageurl . '" alt="' . $single->post_title . '" />';
93
 
94
+ if ($lcp_thumb_class != null){
95
+ $thmbn_class = ' class="' . $lcp_thumb_class . '" />';
96
  $lcp_ytimage = preg_replace("/\>/", $thmbn_class, $lcp_ytimage);
97
+ }
98
+ $lcp_thumbnail .= '<a href="' . get_permalink($single->ID).'">' . $lcp_ytimage . '</a>';
 
99
  }
100
  }
101
  }
list-category-posts.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: List category posts
4
  Plugin URI: https://github.com/picandocodigo/List-Category-Posts
5
  Description: List Category Posts allows you to list posts by category in a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, the number of posts to display and many more parameters. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
6
- Version: 0.66
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
@@ -79,6 +79,7 @@ class ListCategoryPosts{
79
  'catlink_string' => '',
80
  'catlink_tag' =>'',
81
  'catlink_class' => '',
 
82
  'comments' => 'no',
83
  'comments_tag' => '',
84
  'comments_class' => '',
@@ -86,6 +87,7 @@ class ListCategoryPosts{
86
  'thumbnail' => 'no',
87
  'thumbnail_size' => 'thumbnail',
88
  'thumbnail_class' => '',
 
89
  'title_tag' => '',
90
  'title_class' => '',
91
  'title_limit' => '0',
3
  Plugin Name: List category posts
4
  Plugin URI: https://github.com/picandocodigo/List-Category-Posts
5
  Description: List Category Posts allows you to list posts by category in a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, the number of posts to display and many more parameters. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
6
+ Version: 0.67
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
79
  'catlink_string' => '',
80
  'catlink_tag' =>'',
81
  'catlink_class' => '',
82
+ 'child_categories' => 'yes',
83
  'comments' => 'no',
84
  'comments_tag' => '',
85
  'comments_class' => '',
87
  'thumbnail' => 'no',
88
  'thumbnail_size' => 'thumbnail',
89
  'thumbnail_class' => '',
90
+ 'force_thumbnail' => '',
91
  'title_tag' => '',
92
  'title_class' => '',
93
  'title_limit' => '0',
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
  Tested up to: 4.3.1
7
- Stable tag: 0.66
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -112,6 +112,8 @@ When using List Category Posts whithout a category id, name or slug, it will pos
112
 
113
  ==Other ways of selecting what posts to show==
114
 
 
 
115
  * **author_posts** - Get posts by author. Use 'user_nicename' (NOT
116
  name). Example: `[catlist author_posts="fernando"]`
117
 
@@ -199,6 +201,14 @@ theme's directory and customize it. Do not customize the file on the
199
  plugin's directory since this file will be overwritten every time you
200
  update the plugin.
201
 
 
 
 
 
 
 
 
 
202
  ==OTHER PARAMETERS==
203
 
204
  * **conditional_title** - Display a custom title before the posts list.
@@ -303,6 +313,8 @@ Show the full content of the post regardless of whether there is a &lt;!--more--
303
 
304
  * **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]`.
305
 
 
 
306
  * **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]`
307
 
308
  * **thumbnail_class** - Set a CSS class for the thumbnail.
@@ -520,6 +532,11 @@ Template system has changed. Custom templates should be stored in WordPress them
520
 
521
  == Changelog ==
522
 
 
 
 
 
 
523
  = 0.66 =
524
  * Full release notes: https://github.com/picandocodigo/List-Category-Posts/releases/tag/0.66
525
  * Orders the README a bit.
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
  Tested up to: 4.3.1
7
+ Stable tag: 0.67
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
112
 
113
  ==Other ways of selecting what posts to show==
114
 
115
+ * **child_categories** - Exclude/include posts from the child categories. By default they are included. If you have a "Parent Category" and you use: `[catlist name="Parent Category"]`, you'll see posts from it's child categories as if they were posts from the same category. You can use this parameter to exclude these posts: `[catlist name="Parent Category" child_categories=false]`.
116
+
117
  * **author_posts** - Get posts by author. Use 'user_nicename' (NOT
118
  name). Example: `[catlist author_posts="fernando"]`
119
 
201
  plugin's directory since this file will be overwritten every time you
202
  update the plugin.
203
 
204
+ The current page in pagination has its own CSS class:
205
+
206
+ `
207
+ <li class='lcp_currentpage'>current_page</li>
208
+ `
209
+
210
+ So you can style the current page number differently if you want to.
211
+
212
  ==OTHER PARAMETERS==
213
 
214
  * **conditional_title** - Display a custom title before the posts list.
313
 
314
  * **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]`.
315
 
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
+
318
  * **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]`
319
 
320
  * **thumbnail_class** - Set a CSS class for the thumbnail.
532
 
533
  == Changelog ==
534
 
535
+ = 0.67 =
536
+ * Adds custom css class to current page in pagination `lcp_currentpage`.
537
+ * 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 :)
539
+
540
  = 0.66 =
541
  * Full release notes: https://github.com/picandocodigo/List-Category-Posts/releases/tag/0.66
542
  * Orders the README a bit.