List category posts - Version 0.88

Version Description

  • When filtering by a single category, you can add main_cat_only=yes to select only the posts that have this category as their main one (#449).
  • Similar to currenttags, currentterms has been added to support filtering by current post's custom taxonomy terms (#293).
Download this release

Release Info

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

Code changes from version 0.87 to 0.88

include/lcp-category.php CHANGED
@@ -15,6 +15,13 @@ class LcpCategory{
15
  return self::$instance;
16
  }
17
 
 
 
 
 
 
 
 
18
  /**
19
  * Parses category related shortcode parameters and returns
20
  * WP_Query compatible $args array. Also sets $lcp_category_id.
@@ -32,6 +39,7 @@ class LcpCategory{
32
  * @type string $name
33
  * @type string $categorypage
34
  * @type string $child_categories
 
35
  * }
36
  * @param mixed &$lcp_category_id Optional. Updated by this method if necessary.
37
  * @return array WP_Query $args array, @see lcp_categories.
@@ -64,6 +72,9 @@ class LcpCategory{
64
  // This is where the lcp_category_id property of CatList is changed.
65
  $lcp_category_id = $categories;
66
 
 
 
 
67
  return $this->lcp_categories(
68
  $categories, $params['child_categories'], $exclude);
69
  }
@@ -265,4 +276,76 @@ class LcpCategory{
265
 
266
  return implode(',',$categories);
267
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  }
15
  return self::$instance;
16
  }
17
 
18
+ /**
19
+ * Used to store the single main category to filter by.
20
+ *
21
+ * @var int
22
+ */
23
+ private $main_cat;
24
+
25
  /**
26
  * Parses category related shortcode parameters and returns
27
  * WP_Query compatible $args array. Also sets $lcp_category_id.
39
  * @type string $name
40
  * @type string $categorypage
41
  * @type string $child_categories
42
+ * @type string $main_cat_only
43
  * }
44
  * @param mixed &$lcp_category_id Optional. Updated by this method if necessary.
45
  * @return array WP_Query $args array, @see lcp_categories.
72
  // This is where the lcp_category_id property of CatList is changed.
73
  $lcp_category_id = $categories;
74
 
75
+ // Check if only the main category should be used.
76
+ $this->check_main_cat_only( $params[ 'main_cat_only' ], $categories );
77
+
78
  return $this->lcp_categories(
79
  $categories, $params['child_categories'], $exclude);
80
  }
276
 
277
  return implode(',',$categories);
278
  }
279
+
280
+ /**
281
+ * Handles the 'main_cat_only' shortcode parameter.
282
+ *
283
+ * When filtering by main category is enabled, adds
284
+ * a proper filter function to the 'posts_results' hook.
285
+ *
286
+ * @param string $main_cat_only Shortcode parameter value, 'yes' to enable.
287
+ * @param mixed $categories Category ID of the main category to filter by.
288
+ */
289
+ private function check_main_cat_only( $main_cat_only, $categories ) {
290
+ if ( 'yes' === $main_cat_only ) {
291
+ $this->main_cat = intval( $categories );
292
+ add_filter( 'posts_results', [ $this, 'filter_by_main_category' ] );
293
+ }
294
+ }
295
+
296
+ /**
297
+ * Filter method intended for the 'posts_results' hook.
298
+ *
299
+ * Filters the posts array and returns only those that
300
+ * have their main/primary category matching the one saved
301
+ * in the $main_cat private property.
302
+ *
303
+ * @param array $posts WP_Post objects.
304
+ * @return array Filtered WP_Post objects.
305
+ */
306
+ public function filter_by_main_category( $posts ) {
307
+ /* array_values is necessary to fix indexes, WordPress expects posts
308
+ array to have proper numerical indexing but array_filter retains
309
+ original array's keys.
310
+ */
311
+ return array_values( array_filter( $posts, function( $post ) {
312
+ return $this->get_post_primary_category( $post )->term_id === $this->main_cat;
313
+ }));
314
+ }
315
+
316
+ /**
317
+ * Gets the main category of a post.
318
+ *
319
+ * This method accepts a post ID and first tries to get the
320
+ * primary category (a Yoast SEO feature) of the post. If none is found
321
+ * it falls back to the first assigned category on the post's category list.
322
+ *
323
+ * @link https://www.lab21.gr/blog/wordpress-get-primary-category-post/
324
+ *
325
+ * @param int $post_id ID of the post to check.
326
+ * @return mixed Category ID (int) of the post's main category or null if none found.
327
+ */
328
+ private function get_post_primary_category( $post_id ) {
329
+ $return = null;
330
+
331
+ if ( class_exists( 'WPSEO_Primary_Term' ) ) {
332
+ // Show Primary category by Yoast if it is enabled & set
333
+ $wpseo_primary_term = new WPSEO_Primary_Term( 'category', $post_id );
334
+ $primary_term = get_term( $wpseo_primary_term->get_primary_term() ) ;
335
+
336
+ if ( !is_wp_error( $primary_term ) ) {
337
+ $return = $primary_term;
338
+ }
339
+ }
340
+
341
+ if ( empty( $return ) ) {
342
+ $categories_list = get_the_terms( $post_id, 'category' );
343
+
344
+ if ( !empty( $categories_list ) ) {
345
+ $return = $categories_list[0]; //get the first category
346
+ }
347
+ }
348
+
349
+ return $return;
350
+ }
351
  }
include/lcp-catlist.php CHANGED
@@ -79,6 +79,7 @@ class CatList{
79
  'name' => $this->params['name'],
80
  'categorypage' => $this->params['categorypage'],
81
  'child_categories' => $this->params['child_categories'],
 
82
  ], $this->lcp_category_id);
83
  $processed_params = LcpParameters::get_instance()->get_query_params($this->params);
84
  $args = array_merge($args, $processed_params);
@@ -105,6 +106,7 @@ class CatList{
105
  remove_all_filters('posts_orderby');
106
  }
107
  remove_filter('posts_where', array(LcpParameters::get_instance(), 'starting_with'));
 
108
 
109
  return $lcp_query;
110
  }
79
  'name' => $this->params['name'],
80
  'categorypage' => $this->params['categorypage'],
81
  'child_categories' => $this->params['child_categories'],
82
+ 'main_cat_only' => $this->params['main_cat_only'],
83
  ], $this->lcp_category_id);
84
  $processed_params = LcpParameters::get_instance()->get_query_params($this->params);
85
  $args = array_merge($args, $processed_params);
106
  remove_all_filters('posts_orderby');
107
  }
108
  remove_filter('posts_where', array(LcpParameters::get_instance(), 'starting_with'));
109
+ remove_filter('posts_results', [ LcpCategory::get_instance(), 'filter_by_main_category' ]);
110
 
111
  return $lcp_query;
112
  }
include/lcp-parameters.php CHANGED
@@ -2,6 +2,7 @@
2
  require_once LCP_PATH . 'lcp-utils.php';
3
  require_once LCP_PATH . 'lcp-date-query.php';
4
  require_once LCP_PATH . 'lcp-meta-query.php';
 
5
 
6
  class LcpParameters{
7
  // Singleton implementation
@@ -15,6 +16,8 @@ class LcpParameters{
15
  use LcpDateQuery;
16
  // Use Trait for meta query
17
  use LcpMetaQuery;
 
 
18
 
19
  public static function get_instance(){
20
  if( !isset( self::$instance ) ){
@@ -88,7 +91,7 @@ class LcpParameters{
88
  // Current tags
89
  $currenttags = $params['currenttags'];
90
  if ( $currenttags === 'yes' || $currenttags === 'all' ) {
91
- $tags = $this->lcp_get_current_tags();
92
 
93
  if ( !empty($tags) ) {
94
  // OR relationship
@@ -112,26 +115,7 @@ class LcpParameters{
112
  }
113
 
114
  // Custom taxonomy support
115
- // Why didn't I document this?!?
116
- if ( $this->utils->lcp_not_empty('taxonomy') && $this->utils->lcp_not_empty('terms') ){
117
- if ( strpos($params['terms'],'+') !== false ) {
118
- $terms = explode("+",$params['terms']);
119
- $operator = 'AND';
120
- } else {
121
- $terms = explode(",",$params['terms']);
122
- $operator = 'IN';
123
- }
124
-
125
- $args['tax_query'] = array(array(
126
- 'taxonomy' => $params['taxonomy'],
127
- 'field' => 'slug',
128
- 'terms' => $terms,
129
- 'operator' => $operator
130
- ));
131
- }
132
-
133
- // Multiple taxonomies support
134
- $args = $this->lcp_taxonomies($args);
135
 
136
  // Tag support
137
  if ( $this->utils->lcp_not_empty('tags') ) {
@@ -212,36 +196,6 @@ class LcpParameters{
212
  return $args;
213
  }
214
 
215
- private function lcp_taxonomies($args){
216
- // Multiple taxonomies support in the form
217
- // taxonomies_or="tax1:{term1_1,term1_2};tax2:{term2_1,term2_2,term2_3}"
218
- // taxonomies_and="tax1:{term1_1,term1_2};tax2:{term2_1,term2_2,term2_3}"
219
- if ( $this->utils->lcp_not_empty('taxonomies_or') ||
220
- $this->utils->lcp_not_empty('taxonomies_and') ) {
221
- if($this->utils->lcp_not_empty('taxonomies_or')) {
222
- $operator = "OR";
223
- $taxonomies = $this->params['taxonomies_or'];
224
- } else {
225
- $operator = "AND";
226
- $taxonomies = $this->params['taxonomies_and'];
227
- }
228
- $count = preg_match_all('/([^:]+):\{([^:]+)\}(?:;|$)/im', $taxonomies, $matches, PREG_SET_ORDER, 0);
229
- if($count > 0) {
230
- $tax_arr = array('relation' => $operator);
231
- foreach ($matches as $match) {
232
- $tax_term = array(
233
- 'taxonomy' => $match[1],
234
- 'field' => 'slug',
235
- 'terms' => explode(",",$match[2])
236
- );
237
- array_push($tax_arr, $tax_term);
238
- }
239
- $args['tax_query'] = $tax_arr;
240
- }
241
- }
242
- return $args;
243
- }
244
-
245
  private function lcp_types_and_statuses($args){
246
  // Post type, status, parent params:
247
  if($this->utils->lcp_not_empty('post_type')):
@@ -268,15 +222,16 @@ class LcpParameters{
268
  return $args;
269
  }
270
 
271
- private function lcp_get_current_tags(){
272
- $tags = get_the_tags();
273
- $tag_ids = array();
274
- if( !empty($tags) ){
275
- foreach ($tags as $tag) {
276
- array_push($tag_ids, $tag->term_id);
 
277
  }
278
  }
279
- return $tag_ids;
280
  }
281
 
282
  public function starting_with($where){
2
  require_once LCP_PATH . 'lcp-utils.php';
3
  require_once LCP_PATH . 'lcp-date-query.php';
4
  require_once LCP_PATH . 'lcp-meta-query.php';
5
+ require_once LCP_PATH . 'lcp-taxonomies.php';
6
 
7
  class LcpParameters{
8
  // Singleton implementation
16
  use LcpDateQuery;
17
  // Use Trait for meta query
18
  use LcpMetaQuery;
19
+ // Use Trait for custom taxonomies
20
+ use LcpTaxonomies;
21
 
22
  public static function get_instance(){
23
  if( !isset( self::$instance ) ){
91
  // Current tags
92
  $currenttags = $params['currenttags'];
93
  if ( $currenttags === 'yes' || $currenttags === 'all' ) {
94
+ $tags = $this->lcp_get_current_terms( 'post_tag' );
95
 
96
  if ( !empty($tags) ) {
97
  // OR relationship
115
  }
116
 
117
  // Custom taxonomy support
118
+ $args = $this->create_tax_query($args, $params);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
  // Tag support
121
  if ( $this->utils->lcp_not_empty('tags') ) {
196
  return $args;
197
  }
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  private function lcp_types_and_statuses($args){
200
  // Post type, status, parent params:
201
  if($this->utils->lcp_not_empty('post_type')):
222
  return $args;
223
  }
224
 
225
+ // Duplicated in LcpTaxonomies, for now.
226
+ private function lcp_get_current_terms($taxonomy) {
227
+ $terms = get_the_terms(0, $taxonomy);
228
+ $term_ids = array();
229
+ if( !empty( $terms ) ) {
230
+ foreach ( $terms as $term ) {
231
+ array_push( $term_ids, $term->term_id );
232
  }
233
  }
234
+ return $term_ids;
235
  }
236
 
237
  public function starting_with($where){
include/lcp-taxonomies.php ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file defines the LcpTaxonomies trait.
4
+ */
5
+
6
+ /**
7
+ * The LcpTaxonomies trait is inteded to be used in
8
+ * the LcpParameters class. It contains code that builds
9
+ * WP_Meta_Query.
10
+ *
11
+ * All custom taxonomy related code should be in this trait.
12
+ *
13
+ * @see WP_Tax_Query
14
+ */
15
+ trait LcpTaxonomies {
16
+
17
+ /**
18
+ * Parses taxonomy related shortcode parameters.
19
+ *
20
+ * This is the only method of this trait that is inteded to be called
21
+ * directly. It calls helper methods to parse shortcode parameters that
22
+ * select posts by custom taxonomy terms and to build a WP_Tax_Query compatible
23
+ * array of arguments. The 'tax_query' array is only appended to $args
24
+ * if it is not empty i.e. at least one relevant shortcode parameter was used.
25
+ *
26
+ * @param array $args Array of WP_Query arguments.
27
+ * @param array $params Shortcode parameters.
28
+ * @return array The original `$args` with a new 'tax_query' array
29
+ * appended if any customfield options were specified.
30
+ */
31
+ public function create_tax_query( $args, $params ) {
32
+ $tax_query = array();
33
+
34
+ $this->check_simple_taxonomies( $params, $tax_query );
35
+ $this->check_multiple_taxonomies( $params, $tax_query );
36
+ /*
37
+ Display nothing when a post has no terms.
38
+ Note that this will not prevent sticky posts
39
+ from being shown if they match other query parameters,
40
+ e.g. when no category is specified or a sticky post's
41
+ category matches the one given in `id` or `name`.
42
+ #80
43
+ */
44
+ $return_posts = $this->check_current_terms( $params, $tax_query );
45
+ if ( false === $return_posts ) {
46
+ $args['post__in'] = [0];
47
+ }
48
+
49
+ /*
50
+ * If any query clauses were added to $tax_query,
51
+ * it needs to be added to args.
52
+ */
53
+ if ( !empty( $tax_query ) ) {
54
+ $args[ 'tax_query' ] = $tax_query;
55
+ }
56
+
57
+ return $args;
58
+ }
59
+
60
+ /**
61
+ * Handles selecting by term(s) of a single custom taxonomy.
62
+ *
63
+ * The basic usage e.g. `taxonomy="mouse" terms="mickey,minnie" is checked
64
+ * here. Supported relationships: 'and', 'or'.
65
+ *
66
+ * @param array $params Shortcode parameters.
67
+ * @param array &$tax_query WP_Tax_Query compatible arguments.
68
+ */
69
+ private function check_simple_taxonomies( $params, &$tax_query ) {
70
+ if ( !empty( $params[ 'taxonomy' ] ) && !empty( $params[ 'terms' ] ) ) {
71
+ if ( strpos( $params[ 'terms' ], '+' ) !== false ) {
72
+ $terms = explode( "+", $params[ 'terms' ] );
73
+ $operator = 'AND';
74
+ } else {
75
+ $terms = explode( ",", $params[ 'terms' ] );
76
+ $operator = 'IN';
77
+ }
78
+
79
+ $tax_query[] = [
80
+ 'taxonomy' => $params[ 'taxonomy' ],
81
+ 'field' => 'slug',
82
+ 'terms' => $terms,
83
+ 'operator' => $operator
84
+ ];
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Handles selecting by term(s) of multiple custom taxonomies.
90
+ *
91
+ * Parses the second, more advanced, syntax the plugin supports for
92
+ * custom taxonomies. It supports 'or', 'and' relationships for taxonomies
93
+ * but only supports the 'or' relationship for terms.
94
+ *
95
+ * @param array $params Shortcode parameters.
96
+ * @param array &$tax_query WP_Tax_Query compatible arguments.
97
+ */
98
+ private function check_multiple_taxonomies( $params, &$tax_query ) {
99
+ // Multiple taxonomies support in the form
100
+ // taxonomies_or="tax1:{term1_1,term1_2};tax2:{term2_1,term2_2,term2_3}"
101
+ // taxonomies_and="tax1:{term1_1,term1_2};tax2:{term2_1,term2_2,term2_3}"
102
+ if ( !empty( $params[ 'taxonomies_or' ] ) ||
103
+ !empty( $params[ 'taxonomies_and' ] ) ) {
104
+ if ( !empty( $params[ 'taxonomies_or' ] ) ) {
105
+ $operator = 'OR';
106
+ $taxonomies = $params[ 'taxonomies_or' ];
107
+ } else {
108
+ $operator = 'AND';
109
+ $taxonomies = $params[ 'taxonomies_and' ];
110
+ }
111
+ $count = preg_match_all('/([^:]+):\{([^:]+)\}(?:;|$)/im', $taxonomies, $matches, PREG_SET_ORDER, 0);
112
+ if ( $count > 0 ) {
113
+ $tax_query[ 'relation' ] = $operator ;
114
+ foreach ( $matches as $match ) {
115
+ $tax_term = [
116
+ 'taxonomy' => $match[1],
117
+ 'field' => 'slug',
118
+ 'terms' => explode( ',', $match[2] )
119
+ ];
120
+
121
+ $tax_query[] = $tax_term;
122
+ }
123
+ }
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Handles selecting by current post's custom taxonomy term(s).
129
+ *
130
+ * This is analogous to the current implementation of currenttags.
131
+ * In future refactorings the post_tag related code should be moved
132
+ * to this trait. Unlike other 'check_' methods of this trait, this one
133
+ * has a return value. It should return false when currentterms was
134
+ * specified but current post had none matching. The returned value
135
+ * is checked by 'create_tax_query'.
136
+ *
137
+ * @param array $params Shortcode parameters.
138
+ * @param array &$tax_query WP_Tax_Query compatible arguments.
139
+ * @return bool True if current terms were foud, false otherwise.
140
+ */
141
+ private function check_current_terms( $params, &$tax_query ) {
142
+ $currentterms = $params[ 'currentterms' ];
143
+ if ( $currentterms === 'yes' || $currentterms === 'all' ) {
144
+ $terms = $this->get_current_terms( $params[ 'taxonomy' ] );
145
+
146
+ if ( !empty( $terms ) ) {
147
+ // OR relationship
148
+ if ( 'yes' === $currentterms ) {
149
+ $operator = 'IN';
150
+ } else {
151
+ // AND relationship
152
+ $operator = 'AND';
153
+ }
154
+ } else {
155
+ return false;
156
+ }
157
+
158
+ $tax_query[] = [
159
+ 'taxonomy' => $params[ 'taxonomy' ],
160
+ 'field' => 'term_id',
161
+ 'terms' => $terms,
162
+ 'operator' => $operator
163
+ ];
164
+ return true;
165
+ }
166
+ }
167
+
168
+ /**
169
+ * A simple helper to get current post's custom taxonomy terms.
170
+ *
171
+ * @param string $taxonomy Selected custom taxonomy.
172
+ * @return array IDs of current post's terms belonging to $taxonomy.
173
+ *
174
+ * @see get_the_terms
175
+ */
176
+ private function get_current_terms( $taxonomy ) {
177
+ $terms = get_the_terms( 0, $taxonomy );
178
+ $term_ids = array();
179
+ if( !empty( $terms ) ) {
180
+ foreach ( $terms as $term ) {
181
+ array_push( $term_ids, $term->term_id );
182
+ }
183
+ }
184
+ return $term_ids;
185
+ }
186
+ }
include/lcp-thumbnail.php CHANGED
@@ -51,30 +51,30 @@ class LcpThumbnail{
51
  )
52
  );
53
  $lcp_thumbnail .= '</a>';
54
- } else {
55
  // if thumbnail is requested but not found as featured image, grab first image in the content of the post
56
- if ( ($force_thumbnail === 'yes'|| $force_thumbnail === 'true') && preg_match('~<img[^>]*src\s?=\s?[\'"]([^\'"]*)~i',get_the_content(), $imgMatches)) {
57
- $lcp_thumbnail = '<a href="' . esc_url(get_permalink($single->ID)) .
58
- '" title="' . esc_attr($single->post_title) . '">';
59
 
60
- $lcp_thumbnail .= '<img src="' . esc_url($imgMatches[1]) . '" ';
61
- if ( $lcp_thumb_class != null ) { // thumbnail class passed as parameter to shortcode
62
- $lcp_thumbnail .= 'class="' . $lcp_thumb_class . '" ';
63
- }
64
- else { // Otherwise, use this class name
65
- $lcp_thumbnail .= 'class="lcp_thumbnail" ';
66
- }
67
- $lcp_thumbnail .= ' alt="' . esc_attr($single->post_title) . '" /></a>';
68
  }
 
 
 
 
 
 
 
69
  }
70
- } else {
71
- # Check for a YouTube video thumbnail
72
- $lcp_thumbnail = $this->check_youtube_thumbnail($single->content);
73
  }
74
  return $lcp_thumbnail;
75
  }
76
 
77
- private function check_youtube_thumbnail($content){
 
 
78
  # youtube.com/watch?v=id
79
  $yt_pattern = '/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/';
80
  # youtube.com/v[id]
@@ -99,7 +99,7 @@ class LcpThumbnail{
99
  $thmbn_class = ' class="' . $lcp_thumb_class . '" />';
100
  $lcp_ytimage = preg_replace("/\>/", $thmbn_class, $lcp_ytimage);
101
  }
102
- $lcp_thumbnail .= '<a href="' . get_permalink($single->ID).'">' . $lcp_ytimage . '</a>';
103
  }
104
  }
105
  }
51
  )
52
  );
53
  $lcp_thumbnail .= '</a>';
54
+ } else if ( ($force_thumbnail === 'yes'|| $force_thumbnail === 'true') && preg_match('~<img[^>]*src\s?=\s?[\'"]([^\'"]*)~i',get_the_content(), $imgMatches)) {
55
  // if thumbnail is requested but not found as featured image, grab first image in the content of the post
56
+ $lcp_thumbnail = '<a href="' . esc_url(get_permalink($single->ID)) .
57
+ '" title="' . esc_attr($single->post_title) . '">';
 
58
 
59
+ $lcp_thumbnail .= '<img src="' . esc_url($imgMatches[1]) . '" ';
60
+ if ( $lcp_thumb_class != null ) { // thumbnail class passed as parameter to shortcode
61
+ $lcp_thumbnail .= 'class="' . $lcp_thumb_class . '" ';
 
 
 
 
 
62
  }
63
+ else { // Otherwise, use this class name
64
+ $lcp_thumbnail .= 'class="lcp_thumbnail" ';
65
+ }
66
+ $lcp_thumbnail .= ' alt="' . esc_attr($single->post_title) . '" /></a>';
67
+ } else {
68
+ # Check for a YouTube video thumbnail
69
+ $lcp_thumbnail = $this->check_youtube_thumbnail($single, $lcp_thumb_class);
70
  }
 
 
 
71
  }
72
  return $lcp_thumbnail;
73
  }
74
 
75
+ private function check_youtube_thumbnail($single, $lcp_thumb_class){
76
+ $content = $single->content;
77
+
78
  # youtube.com/watch?v=id
79
  $yt_pattern = '/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/';
80
  # youtube.com/v[id]
99
  $thmbn_class = ' class="' . $lcp_thumb_class . '" />';
100
  $lcp_ytimage = preg_replace("/\>/", $thmbn_class, $lcp_ytimage);
101
  }
102
+ return '<a href="' . get_permalink($single->ID).'">' . $lcp_ytimage . '</a>';
103
  }
104
  }
105
  }
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.87
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
@@ -130,6 +130,7 @@ class ListCategoryPosts{
130
  'taxonomies_and' => '',
131
  'taxonomies_or' => '',
132
  'terms' => '',
 
133
  'categorypage' => '',
134
  'category_count' => '',
135
  'category_description' => 'no',
@@ -169,6 +170,7 @@ class ListCategoryPosts{
169
  'keep_orderby_filters' => '',
170
  'ignore_sticky_posts' => '',
171
  'cat_sticky_posts' => '',
 
172
  );
173
  }
174
  return self::$default_params;
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.88
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
130
  'taxonomies_and' => '',
131
  'taxonomies_or' => '',
132
  'terms' => '',
133
+ 'currentterms' => '',
134
  'categorypage' => '',
135
  'category_count' => '',
136
  'category_description' => 'no',
170
  'keep_orderby_filters' => '',
171
  'ignore_sticky_posts' => '',
172
  'cat_sticky_posts' => '',
173
+ 'main_cat_only' => '',
174
  );
175
  }
176
  return self::$default_params;
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: fernandobt, zymeth25
3
  Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
- Tested up to: 6.0
7
  Requires PHP: 5.4
8
- Stable tag: 0.87
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -237,6 +237,11 @@ Template system has changed. Custom templates should be stored in WordPress them
237
 
238
  == Changelog ==
239
 
 
 
 
 
 
240
  = 0.87 =
241
 
242
  * **New feature**: use `keep_orderby_filters=yes` to prevent the plugin from removing 'posts_orderby' filters added by other plugins/themes.
3
  Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
+ Tested up to: 6.1
7
  Requires PHP: 5.4
8
+ Stable tag: 0.88
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
237
 
238
  == Changelog ==
239
 
240
+ = 0.88 =
241
+
242
+ * When filtering by a single category, you can add `main_cat_only=yes` to select only the posts that have this category as their main one (#449).
243
+ * Similar to `currenttags`, `currentterms` has been added to support filtering by current post's custom taxonomy terms (#293).
244
+
245
  = 0.87 =
246
 
247
  * **New feature**: use `keep_orderby_filters=yes` to prevent the plugin from removing 'posts_orderby' filters added by other plugins/themes.