Display Posts Shortcode - Version 2.9.0

Version Description

Download this release

Release Info

Developer billerickson
Plugin Icon 128x128 Display Posts Shortcode
Version 2.9.0
Comparing to
See all releases

Code changes from version 2.8.0 to 2.9.0

Files changed (3) hide show
  1. CHANGELOG.md +10 -0
  2. display-posts-shortcode.php +27 -8
  3. readme.txt +9 -2
CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
  # Change Log
2
  All notable changes to this project will be documented in this file, formatted via [this recommendation](http://keepachangelog.com/).
3
 
 
 
 
 
 
 
 
 
 
 
4
  ### [2.8.0]
5
  #### Added
6
  * Set include_link="false" to remove link from post title and image, see [#137](https://github.com/billerickson/display-posts-shortcode/pull/137)
1
  # Change Log
2
  All notable changes to this project will be documented in this file, formatted via [this recommendation](http://keepachangelog.com/).
3
 
4
+ ### [2.9.0]
5
+ #### Added
6
+ * New parameter `exclude` for excluding specific post IDs, see #154
7
+ * New parameter `category_id` for specifying category by ID (note: only accepts a single ID), see #156
8
+ * New parameter `include_date_modified` for displaying the date the post was last updated, see #150
9
+
10
+ #### Fixed
11
+ * Shortcode title now appears above the wrapper (ul/ol/div), fixing invalid markup, see #165
12
+ * Limit visibility to readable posts
13
+
14
  ### [2.8.0]
15
  #### Added
16
  * Set include_link="false" to remove link from post title and image, see [#137](https://github.com/billerickson/display-posts-shortcode/pull/137)
display-posts-shortcode.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Display Posts Shortcode
4
  * Plugin URI: http://www.billerickson.net/shortcode-to-display-posts/
5
  * Description: Display a listing of posts using the [display-posts] shortcode
6
- * Version: 2.8.0
7
  * Author: Bill Erickson
8
  * Author URI: http://www.billerickson.net
9
  *
@@ -15,7 +15,7 @@
15
  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
  *
17
  * @package Display Posts
18
- * @version 2.8.0
19
  * @author Bill Erickson <bill@billerickson.net>
20
  * @copyright Copyright (c) 2011, Bill Erickson
21
  * @link http://www.billerickson.net/shortcode-to-display-posts/
@@ -40,6 +40,7 @@ function be_display_posts_shortcode( $atts ) {
40
  'author' => '',
41
  'category' => '',
42
  'category_display' => '',
 
43
  'category_label' => 'Posted in: ',
44
  'content_class' => 'content',
45
  'date_format' => '(n/j/Y)',
@@ -54,6 +55,7 @@ function be_display_posts_shortcode( $atts ) {
54
  'excerpt_length' => false,
55
  'excerpt_more' => false,
56
  'excerpt_more_link' => false,
 
57
  'exclude_current' => false,
58
  'id' => false,
59
  'ignore_sticky_posts' => false,
@@ -61,6 +63,7 @@ function be_display_posts_shortcode( $atts ) {
61
  'include_author' => false,
62
  'include_content' => false,
63
  'include_date' => false,
 
64
  'include_excerpt' => false,
65
  'include_link' => true,
66
  'include_title' => true,
@@ -93,6 +96,7 @@ function be_display_posts_shortcode( $atts ) {
93
  $author = sanitize_text_field( $atts['author'] );
94
  $category = sanitize_text_field( $atts['category'] );
95
  $category_display = 'true' == $atts['category_display'] ? 'category' : sanitize_text_field( $atts['category_display'] );
 
96
  $category_label = sanitize_text_field( $atts['category_label'] );
97
  $content_class = array_map( 'sanitize_html_class', ( explode( ' ', $atts['content_class'] ) ) );
98
  $date_format = sanitize_text_field( $atts['date_format'] );
@@ -106,6 +110,7 @@ function be_display_posts_shortcode( $atts ) {
106
  $excerpt_length = intval( $atts['excerpt_length'] );
107
  $excerpt_more = sanitize_text_field( $atts['excerpt_more'] );
108
  $excerpt_more_link = filter_var( $atts['excerpt_more_link'], FILTER_VALIDATE_BOOLEAN );
 
109
  $exclude_current = filter_var( $atts['exclude_current'], FILTER_VALIDATE_BOOLEAN );
110
  $id = $atts['id']; // Sanitized later as an array of integers
111
  $ignore_sticky_posts = filter_var( $atts['ignore_sticky_posts'], FILTER_VALIDATE_BOOLEAN );
@@ -114,6 +119,7 @@ function be_display_posts_shortcode( $atts ) {
114
  $include_author = filter_var( $atts['include_author'], FILTER_VALIDATE_BOOLEAN );
115
  $include_content = filter_var( $atts['include_content'], FILTER_VALIDATE_BOOLEAN );
116
  $include_date = filter_var( $atts['include_date'], FILTER_VALIDATE_BOOLEAN );
 
117
  $include_excerpt = filter_var( $atts['include_excerpt'], FILTER_VALIDATE_BOOLEAN );
118
  $include_link = filter_var( $atts['include_link'], FILTER_VALIDATE_BOOLEAN );
119
  $meta_key = sanitize_text_field( $atts['meta_key'] );
@@ -144,9 +150,11 @@ function be_display_posts_shortcode( $atts ) {
144
 
145
  // Set up initial query for post
146
  $args = array(
 
147
  'category_name' => $category,
148
  'order' => $order,
149
  'orderby' => $orderby,
 
150
  'post_type' => explode( ',', $post_type ),
151
  'posts_per_page' => $posts_per_page,
152
  'tag' => $tag,
@@ -250,9 +258,17 @@ function be_display_posts_shortcode( $atts ) {
250
  $args['post__in'] = $posts_in;
251
  }
252
 
253
- // If Exclude Current
254
- if( is_singular() && $exclude_current )
255
- $args['post__not_in'] = array( get_the_ID() );
 
 
 
 
 
 
 
 
256
 
257
  // Post Author
258
  if( !empty( $author ) ) {
@@ -408,8 +424,11 @@ function be_display_posts_shortcode( $atts ) {
408
 
409
  }
410
 
411
- if ( $include_date )
412
  $date = ' <span class="date">' . get_the_date( $date_format ) . '</span>';
 
 
 
413
 
414
  if( $include_author )
415
  /**
@@ -530,7 +549,7 @@ function be_display_posts_shortcode( $atts ) {
530
  */
531
  $close = apply_filters( 'display_posts_shortcode_wrapper_close', '</' . $wrapper . '>', $original_atts );
532
 
533
- $return = $open;
534
 
535
  if( $shortcode_title ) {
536
 
@@ -547,7 +566,7 @@ function be_display_posts_shortcode( $atts ) {
547
  $return .= '<' . $title_tag . ' class="display-posts-title">' . $shortcode_title . '</' . $title_tag . '>' . "\n";
548
  }
549
 
550
- $return .= $inner . $close;
551
 
552
  return $return;
553
  }
3
  * Plugin Name: Display Posts Shortcode
4
  * Plugin URI: http://www.billerickson.net/shortcode-to-display-posts/
5
  * Description: Display a listing of posts using the [display-posts] shortcode
6
+ * Version: 2.9.0
7
  * Author: Bill Erickson
8
  * Author URI: http://www.billerickson.net
9
  *
15
  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
  *
17
  * @package Display Posts
18
+ * @version 2.9.0
19
  * @author Bill Erickson <bill@billerickson.net>
20
  * @copyright Copyright (c) 2011, Bill Erickson
21
  * @link http://www.billerickson.net/shortcode-to-display-posts/
40
  'author' => '',
41
  'category' => '',
42
  'category_display' => '',
43
+ 'category_id' => false,
44
  'category_label' => 'Posted in: ',
45
  'content_class' => 'content',
46
  'date_format' => '(n/j/Y)',
55
  'excerpt_length' => false,
56
  'excerpt_more' => false,
57
  'excerpt_more_link' => false,
58
+ 'exclude' => false,
59
  'exclude_current' => false,
60
  'id' => false,
61
  'ignore_sticky_posts' => false,
63
  'include_author' => false,
64
  'include_content' => false,
65
  'include_date' => false,
66
+ 'include_date_modified'=> false,
67
  'include_excerpt' => false,
68
  'include_link' => true,
69
  'include_title' => true,
96
  $author = sanitize_text_field( $atts['author'] );
97
  $category = sanitize_text_field( $atts['category'] );
98
  $category_display = 'true' == $atts['category_display'] ? 'category' : sanitize_text_field( $atts['category_display'] );
99
+ $category_id = intval( $atts['category_id'] );
100
  $category_label = sanitize_text_field( $atts['category_label'] );
101
  $content_class = array_map( 'sanitize_html_class', ( explode( ' ', $atts['content_class'] ) ) );
102
  $date_format = sanitize_text_field( $atts['date_format'] );
110
  $excerpt_length = intval( $atts['excerpt_length'] );
111
  $excerpt_more = sanitize_text_field( $atts['excerpt_more'] );
112
  $excerpt_more_link = filter_var( $atts['excerpt_more_link'], FILTER_VALIDATE_BOOLEAN );
113
+ $exclude = $atts['exclude']; // Sanitized later as an array of integers
114
  $exclude_current = filter_var( $atts['exclude_current'], FILTER_VALIDATE_BOOLEAN );
115
  $id = $atts['id']; // Sanitized later as an array of integers
116
  $ignore_sticky_posts = filter_var( $atts['ignore_sticky_posts'], FILTER_VALIDATE_BOOLEAN );
119
  $include_author = filter_var( $atts['include_author'], FILTER_VALIDATE_BOOLEAN );
120
  $include_content = filter_var( $atts['include_content'], FILTER_VALIDATE_BOOLEAN );
121
  $include_date = filter_var( $atts['include_date'], FILTER_VALIDATE_BOOLEAN );
122
+ $include_date_modified= filter_var( $atts['include_date_modified'], FILTER_VALIDATE_BOOLEAN );
123
  $include_excerpt = filter_var( $atts['include_excerpt'], FILTER_VALIDATE_BOOLEAN );
124
  $include_link = filter_var( $atts['include_link'], FILTER_VALIDATE_BOOLEAN );
125
  $meta_key = sanitize_text_field( $atts['meta_key'] );
150
 
151
  // Set up initial query for post
152
  $args = array(
153
+ 'cat' => $category_id,
154
  'category_name' => $category,
155
  'order' => $order,
156
  'orderby' => $orderby,
157
+ 'perm' => 'readable',
158
  'post_type' => explode( ',', $post_type ),
159
  'posts_per_page' => $posts_per_page,
160
  'tag' => $tag,
258
  $args['post__in'] = $posts_in;
259
  }
260
 
261
+ // If Exclude
262
+ $post__not_in = array();
263
+ if( !empty( $exclude ) ) {
264
+ $post__not_in = array_map( 'intval', explode( ',', $exclude ) );
265
+ }
266
+ if( is_singular() && $exclude_current ) {
267
+ $post__not_in[] = get_the_ID();
268
+ }
269
+ if( !empty( $post__not_in ) ) {
270
+ $args['post__not_in'] = $post__not_in;
271
+ }
272
 
273
  // Post Author
274
  if( !empty( $author ) ) {
424
 
425
  }
426
 
427
+ if ( $include_date ) {
428
  $date = ' <span class="date">' . get_the_date( $date_format ) . '</span>';
429
+ } elseif ( $include_date_modified ) {
430
+ $date = ' <span class="date">' . get_the_modified_date( $date_format ) . '</span>';
431
+ }
432
 
433
  if( $include_author )
434
  /**
549
  */
550
  $close = apply_filters( 'display_posts_shortcode_wrapper_close', '</' . $wrapper . '>', $original_atts );
551
 
552
+ $return = '';
553
 
554
  if( $shortcode_title ) {
555
 
566
  $return .= '<' . $title_tag . ' class="display-posts-title">' . $shortcode_title . '</' . $title_tag . '>' . "\n";
567
  }
568
 
569
+ $return .= $open . $inner . $close;
570
 
571
  return $return;
572
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: billerickson
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MQKRBRFVRUV8C
4
  Tags: shortcode, pages, posts, page, query, display, list
5
  Requires at least: 3.0
6
- Tested up to: 4.7
7
- Stable tag: 2.8.0
8
 
9
  Display a listing of posts using the [display-posts] shortcode
10
 
@@ -30,6 +30,13 @@ Add the shortcode in a post or page, and use the arguments to query based on tag
30
 
31
  == Changelog ==
32
 
 
 
 
 
 
 
 
33
  **Version 2.8.0**
34
  * Added include_link="false" to remove link from post title and image, see [#137](https://github.com/billerickson/display-posts-shortcode/pull/137)
35
  * Fixed category display when using multiple post types, see [#143](https://github.com/billerickson/display-posts-shortcode/issues/143)
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MQKRBRFVRUV8C
4
  Tags: shortcode, pages, posts, page, query, display, list
5
  Requires at least: 3.0
6
+ Tested up to: 4.8
7
+ Stable tag: 2.9.0
8
 
9
  Display a listing of posts using the [display-posts] shortcode
10
 
30
 
31
  == Changelog ==
32
 
33
+ **Version 2.9.0**
34
+ * New parameter `exclude` for excluding specific post IDs, see [#154](https://github.com/billerickson/display-posts-shortcode/issues/154)
35
+ * New parameter `category_id` for specifying category by ID (note: only accepts a single ID), see [#156](https://github.com/billerickson/display-posts-shortcode/issues/156)
36
+ * New parameter `include_date_modified` for displaying the date the post was last updated, see [#150](https://github.com/billerickson/display-posts-shortcode/issues/150)
37
+ * Shortcode title now appears above the wrapper (ul/ol/div), fixing invalid markup, see [#165](https://github.com/billerickson/display-posts-shortcode/issues/165)
38
+ * Limit visibility to readable posts
39
+
40
  **Version 2.8.0**
41
  * Added include_link="false" to remove link from post title and image, see [#137](https://github.com/billerickson/display-posts-shortcode/pull/137)
42
  * Fixed category display when using multiple post types, see [#143](https://github.com/billerickson/display-posts-shortcode/issues/143)