Display Posts Shortcode - Version 2.6.2

Version Description

Download this release

Release Info

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

Code changes from version 2.6.1 to 2.6.2

Files changed (2) hide show
  1. display-posts-shortcode.php +28 -7
  2. readme.txt +13 -6
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.6.1
7
  * Author: Bill Erickson
8
  * Author URI: http://www.billerickson.net
9
  *
@@ -57,6 +57,7 @@ function be_display_posts_shortcode( $atts ) {
57
  'category' => '',
58
  'category_display' => '',
59
  'category_label' => 'Posted in: ',
 
60
  'date_format' => '(n/j/Y)',
61
  'date' => '',
62
  'date_column' => 'post_date',
@@ -68,6 +69,7 @@ function be_display_posts_shortcode( $atts ) {
68
  'display_posts_off' => false,
69
  'excerpt_length' => false,
70
  'excerpt_more' => false,
 
71
  'exclude_current' => false,
72
  'id' => false,
73
  'ignore_sticky_posts' => false,
@@ -106,6 +108,7 @@ function be_display_posts_shortcode( $atts ) {
106
  $category = sanitize_text_field( $atts['category'] );
107
  $category_display = 'true' == $atts['category_display'] ? 'category' : sanitize_text_field( $atts['category_display'] );
108
  $category_label = sanitize_text_field( $atts['category_label'] );
 
109
  $date_format = sanitize_text_field( $atts['date_format'] );
110
  $date = sanitize_text_field( $atts['date'] );
111
  $date_column = sanitize_text_field( $atts['date_column'] );
@@ -116,6 +119,7 @@ function be_display_posts_shortcode( $atts ) {
116
  $date_query_compare = sanitize_text_field( $atts['date_query_compare'] );
117
  $excerpt_length = intval( $atts['excerpt_length'] );
118
  $excerpt_more = sanitize_text_field( $atts['excerpt_more'] );
 
119
  $exclude_current = filter_var( $atts['exclude_current'], FILTER_VALIDATE_BOOLEAN );
120
  $id = $atts['id']; // Sanitized later as an array of integers
121
  $ignore_sticky_posts = filter_var( $atts['ignore_sticky_posts'], FILTER_VALIDATE_BOOLEAN );
@@ -396,6 +400,8 @@ function be_display_posts_shortcode( $atts ) {
396
  if ( $include_title ) {
397
  /** This filter is documented in wp-includes/link-template.php */
398
  $title = '<a class="title" href="' . apply_filters( 'the_permalink', get_permalink() ) . '">' . get_the_title() . '</a>';
 
 
399
  }
400
 
401
  if ( $image_size && has_post_thumbnail() )
@@ -415,15 +421,30 @@ function be_display_posts_shortcode( $atts ) {
415
  $author = apply_filters( 'display_posts_shortcode_author', ' <span class="author">by ' . get_the_author() . '</span>' );
416
 
417
  if ( $include_excerpt ) {
418
- $excerpt_length = $excerpt_length ? $excerpt_length : apply_filters( 'excerpt_length', 55 );
419
- $excerpt_more = $excerpt_more ? $excerpt_more : apply_filters( 'excerpt_more', ' ' . '[&hellip;]' );
420
- $excerpt = ' <span class="excerpt-dash">-</span> <span class="excerpt">' . wp_trim_words( get_the_excerpt(), $excerpt_length, $excerpt_more ) . '</span>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  }
422
 
423
  if( $include_content ) {
424
  add_filter( 'shortcode_atts_display-posts', 'be_display_posts_off', 10, 3 );
425
  /** This filter is documented in wp-includes/post-template.php */
426
- $content = '<div class="content">' . apply_filters( 'the_content', get_the_content() ) . '</div>';
427
  remove_filter( 'shortcode_atts_display-posts', 'be_display_posts_off', 10, 3 );
428
  }
429
 
@@ -572,7 +593,7 @@ function be_sanitize_date_time( $date_time, $type = 'date', $accepts_string = fa
572
  // Defaults to 2001 for years, January for months, and 1 for days.
573
  $year = $month = $day = 1;
574
 
575
- if ( count( $parts >= 3 ) ) {
576
  list( $year, $month, $day ) = $parts;
577
 
578
  $year = ( $year >= 1 && $year <= 9999 ) ? $year : 1;
@@ -649,4 +670,4 @@ function be_display_posts_off( $out, $pairs, $atts ) {
649
  */
650
  $out['display_posts_off'] = apply_filters( 'display_posts_shortcode_inception_override', true );
651
  return $out;
652
- }
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.6.2
7
  * Author: Bill Erickson
8
  * Author URI: http://www.billerickson.net
9
  *
57
  'category' => '',
58
  'category_display' => '',
59
  'category_label' => 'Posted in: ',
60
+ 'content_class' => 'content',
61
  'date_format' => '(n/j/Y)',
62
  'date' => '',
63
  'date_column' => 'post_date',
69
  'display_posts_off' => false,
70
  'excerpt_length' => false,
71
  'excerpt_more' => false,
72
+ 'excerpt_more_link' => false,
73
  'exclude_current' => false,
74
  'id' => false,
75
  'ignore_sticky_posts' => false,
108
  $category = sanitize_text_field( $atts['category'] );
109
  $category_display = 'true' == $atts['category_display'] ? 'category' : sanitize_text_field( $atts['category_display'] );
110
  $category_label = sanitize_text_field( $atts['category_label'] );
111
+ $content_class = array_map( 'sanitize_html_class', ( explode( ' ', $atts['content_class'] ) ) );
112
  $date_format = sanitize_text_field( $atts['date_format'] );
113
  $date = sanitize_text_field( $atts['date'] );
114
  $date_column = sanitize_text_field( $atts['date_column'] );
119
  $date_query_compare = sanitize_text_field( $atts['date_query_compare'] );
120
  $excerpt_length = intval( $atts['excerpt_length'] );
121
  $excerpt_more = sanitize_text_field( $atts['excerpt_more'] );
122
+ $excerpt_more_link = filter_var( $atts['excerpt_more_link'], FILTER_VALIDATE_BOOLEAN );
123
  $exclude_current = filter_var( $atts['exclude_current'], FILTER_VALIDATE_BOOLEAN );
124
  $id = $atts['id']; // Sanitized later as an array of integers
125
  $ignore_sticky_posts = filter_var( $atts['ignore_sticky_posts'], FILTER_VALIDATE_BOOLEAN );
400
  if ( $include_title ) {
401
  /** This filter is documented in wp-includes/link-template.php */
402
  $title = '<a class="title" href="' . apply_filters( 'the_permalink', get_permalink() ) . '">' . get_the_title() . '</a>';
403
+ } else {
404
+ $title = '';
405
  }
406
 
407
  if ( $image_size && has_post_thumbnail() )
421
  $author = apply_filters( 'display_posts_shortcode_author', ' <span class="author">by ' . get_the_author() . '</span>' );
422
 
423
  if ( $include_excerpt ) {
424
+
425
+ // Custom build excerpt based on shortcode parameters
426
+ if( $excerpt_length || $excerpt_more || $excerpt_more_link ) {
427
+
428
+ $length = $excerpt_length ? $excerpt_length : apply_filters( 'excerpt_length', 55 );
429
+ $more = $excerpt_more ? $excerpt_more : apply_filters( 'excerpt_more', '' );
430
+ $more = $excerpt_more_link ? ' <a href="' . get_permalink() . '">' . $more . '</a>' : ' ' . $more;
431
+
432
+ $excerpt = has_excerpt() ? $post->post_excerpt . $more : wp_trim_words( $post->post_content, $length, $more );
433
+
434
+ // Use default, can customize with WP filters
435
+ } else {
436
+ $excerpt = get_the_excerpt();
437
+ }
438
+
439
+ $excerpt = ' <span class="excerpt-dash">-</span> <span class="excerpt">' . $excerpt . '</span>';
440
+
441
+
442
  }
443
 
444
  if( $include_content ) {
445
  add_filter( 'shortcode_atts_display-posts', 'be_display_posts_off', 10, 3 );
446
  /** This filter is documented in wp-includes/post-template.php */
447
+ $content = '<div class="' . implode( ' ', $content_class ) . '">' . apply_filters( 'the_content', get_the_content() ) . '</div>';
448
  remove_filter( 'shortcode_atts_display-posts', 'be_display_posts_off', 10, 3 );
449
  }
450
 
593
  // Defaults to 2001 for years, January for months, and 1 for days.
594
  $year = $month = $day = 1;
595
 
596
+ if ( count( $parts ) >= 3 ) {
597
  list( $year, $month, $day ) = $parts;
598
 
599
  $year = ( $year >= 1 && $year <= 9999 ) ? $year : 1;
670
  */
671
  $out['display_posts_off'] = apply_filters( 'display_posts_shortcode_inception_override', true );
672
  return $out;
673
+ }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: shortcode, pages, posts, page, query, display, list
5
  Requires at least: 3.0
6
  Tested up to: 4.5.2
7
- Stable tag: 2.6.1
8
 
9
  Display a listing of posts using the [display-posts] shortcode
10
 
@@ -12,13 +12,14 @@ Display a listing of posts using the [display-posts] shortcode
12
 
13
  The *Display Posts Shortcode* was written to allow users to easily display listings of posts without knowing PHP or editing template files.
14
 
15
- Add the shortcode in a post or page, and use the arguments to query based on tag, category, post type, and many other possibilities (see the Arguments). I've also added some extra options to display something more than just the title: include_date, include_excerpt, and image_size.
16
 
17
- See the [WordPress Codex](http://codex.wordpress.org/Class_Reference/WP_Query) for information on using the arguments.
 
 
 
 
18
 
19
- [Documentation](https://github.com/billerickson/display-posts-shortcode/wiki)
20
-
21
- **No support will be provided by the developer**
22
 
23
  == Installation ==
24
 
@@ -29,6 +30,12 @@ See the [WordPress Codex](http://codex.wordpress.org/Class_Reference/WP_Query) f
29
 
30
  == Changelog ==
31
 
 
 
 
 
 
 
32
  **Version 2.6.1**
33
  * Fix issue with manually specified excerpts
34
 
4
  Tags: shortcode, pages, posts, page, query, display, list
5
  Requires at least: 3.0
6
  Tested up to: 4.5.2
7
+ Stable tag: 2.6.2
8
 
9
  Display a listing of posts using the [display-posts] shortcode
10
 
12
 
13
  The *Display Posts Shortcode* was written to allow users to easily display listings of posts without knowing PHP or editing template files.
14
 
15
+ Add the shortcode in a post or page, and use the arguments to query based on tag, category, post type, and many other possibilities. You can also customize the output with parameters like: include_date, include_excerpt, and image_size.
16
 
17
+ * [Available Parameters](https://github.com/billerickson/display-posts-shortcode/blob/master/README.md#parameters)
18
+ * [Customization with Filters](https://github.com/billerickson/display-posts-shortcode/wiki#customization-with-filters)
19
+ * [Extension Plugins](https://github.com/billerickson/display-posts-shortcode/wiki#extension-plugins)
20
+ * [Full Change Log](https://github.com/billerickson/display-posts-shortcode/blob/master/CHANGELOG.md)
21
+ * [View on GitHub](https://github.com/billerickson/display-posts-shortcode)
22
 
 
 
 
23
 
24
  == Installation ==
25
 
30
 
31
  == Changelog ==
32
 
33
+ **Version 2.6.2**
34
+ * More improvements to excerpts, see #110
35
+ * Added content_class parameter
36
+ * Fix date query bug, see #108
37
+ * Fixed undefined variable notice if include_title="false"
38
+
39
  **Version 2.6.1**
40
  * Fix issue with manually specified excerpts
41