Version Description
Download this release
Release Info
Developer | billerickson |
Plugin | Display Posts Shortcode |
Version | 2.7.0 |
Comparing to | |
See all releases |
Code changes from version 2.6.2 to 2.7.0
- display-posts-shortcode.php +115 -122
- readme.txt +8 -1
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.
|
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.
|
19 |
* @author Bill Erickson <bill@billerickson.net>
|
20 |
* @copyright Copyright (c) 2011, Bill Erickson
|
21 |
* @link http://www.billerickson.net/shortcode-to-display-posts/
|
@@ -25,22 +25,7 @@
|
|
25 |
|
26 |
/**
|
27 |
* To Customize, use the following filters:
|
28 |
-
*
|
29 |
-
* `shortcode_atts_display-posts`
|
30 |
-
* For customizing the default shortode arguments
|
31 |
-
*
|
32 |
-
* `display_posts_shortcode_args`
|
33 |
-
* For customizing the $args passed to WP_Query
|
34 |
-
*
|
35 |
-
* `display_posts_shortcode_output`
|
36 |
-
* For customizing the output of individual posts.
|
37 |
-
* Example: https://gist.github.com/1175575#file_display_posts_shortcode_output.php
|
38 |
-
*
|
39 |
-
* `display_posts_shortcode_wrapper_open`
|
40 |
-
* display_posts_shortcode_wrapper_close`
|
41 |
-
* For customizing the outer markup of the whole listing. By default it is a <ul> but
|
42 |
-
* can be changed to <ol> or <div> using the 'wrapper' attribute, or by using this filter.
|
43 |
-
* Example: https://gist.github.com/1270278
|
44 |
*/
|
45 |
|
46 |
// Create the shortcode
|
@@ -52,100 +37,102 @@ function be_display_posts_shortcode( $atts ) {
|
|
52 |
|
53 |
// Pull in shortcode attributes and set defaults
|
54 |
$atts = shortcode_atts( array(
|
55 |
-
'
|
56 |
-
'
|
57 |
-
'
|
58 |
-
'
|
59 |
-
'
|
60 |
-
'
|
61 |
-
'
|
62 |
-
'
|
63 |
-
'
|
64 |
-
'
|
65 |
-
'
|
66 |
-
'
|
67 |
-
'
|
68 |
-
'
|
69 |
-
'
|
70 |
-
'
|
71 |
-
'
|
72 |
-
'
|
73 |
-
'
|
74 |
-
'
|
75 |
-
'
|
76 |
-
'
|
77 |
-
'
|
78 |
-
'
|
79 |
-
'
|
80 |
-
'
|
81 |
-
'
|
82 |
-
'
|
83 |
-
'
|
84 |
-
'
|
85 |
-
'
|
86 |
-
'
|
87 |
-
'
|
88 |
-
'
|
89 |
-
'
|
90 |
-
'
|
91 |
-
'
|
92 |
-
'
|
93 |
-
'
|
94 |
-
'tax_term'
|
95 |
-
'taxonomy'
|
96 |
-
'time'
|
97 |
-
'
|
98 |
-
'
|
99 |
-
'
|
|
|
100 |
), $atts, 'display-posts' );
|
101 |
|
102 |
// End early if shortcode should be turned off
|
103 |
if( $atts['display_posts_off'] )
|
104 |
return;
|
105 |
|
106 |
-
$
|
107 |
-
$
|
108 |
-
$
|
109 |
-
$
|
110 |
-
$
|
111 |
-
$
|
112 |
-
$
|
113 |
-
$
|
114 |
-
$
|
115 |
-
$
|
116 |
-
$
|
117 |
-
$
|
118 |
-
$
|
119 |
-
$
|
120 |
-
$
|
121 |
-
$
|
122 |
-
$
|
123 |
-
$
|
124 |
-
$
|
125 |
-
$
|
126 |
-
$
|
127 |
-
$
|
128 |
-
$
|
129 |
-
$
|
130 |
-
$
|
131 |
-
$
|
132 |
-
$
|
133 |
-
$
|
134 |
-
$
|
135 |
-
$
|
136 |
-
$
|
137 |
-
$
|
138 |
-
$
|
139 |
-
$
|
140 |
-
$
|
141 |
-
$
|
142 |
-
$
|
143 |
-
$
|
144 |
-
$tax_term
|
145 |
-
$taxonomy
|
146 |
-
$time
|
147 |
-
$
|
148 |
-
$
|
|
|
149 |
|
150 |
if( !empty( $wrapper_class ) )
|
151 |
$wrapper_class = ' class="' . implode( ' ', $wrapper_class ) . '"';
|
@@ -308,14 +295,15 @@ function be_display_posts_shortcode( $atts ) {
|
|
308 |
// Validate operator
|
309 |
if( !in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) )
|
310 |
$tax_operator = 'IN';
|
311 |
-
|
312 |
$tax_args = array(
|
313 |
'tax_query' => array(
|
314 |
array(
|
315 |
-
'taxonomy'
|
316 |
-
'field'
|
317 |
-
'terms'
|
318 |
-
'operator'
|
|
|
319 |
)
|
320 |
)
|
321 |
);
|
@@ -334,12 +322,14 @@ function be_display_posts_shortcode( $atts ) {
|
|
334 |
$terms = explode( ', ', sanitize_text_field( $original_atts['tax_' . $count . '_term'] ) );
|
335 |
$tax_operator = isset( $original_atts['tax_' . $count . '_operator'] ) ? $original_atts['tax_' . $count . '_operator'] : 'IN';
|
336 |
$tax_operator = in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) ? $tax_operator : 'IN';
|
|
|
337 |
|
338 |
$tax_args['tax_query'][] = array(
|
339 |
-
'taxonomy'
|
340 |
-
'field'
|
341 |
-
'terms'
|
342 |
-
'operator'
|
|
|
343 |
);
|
344 |
|
345 |
$count++;
|
@@ -418,7 +408,7 @@ function be_display_posts_shortcode( $atts ) {
|
|
418 |
*
|
419 |
* @param string $author_output HTML markup to display author information.
|
420 |
*/
|
421 |
-
$author = apply_filters( 'display_posts_shortcode_author', ' <span class="author">by ' . get_the_author() . '</span>' );
|
422 |
|
423 |
if ( $include_excerpt ) {
|
424 |
|
@@ -428,8 +418,15 @@ function be_display_posts_shortcode( $atts ) {
|
|
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 {
|
@@ -486,10 +483,6 @@ function be_display_posts_shortcode( $atts ) {
|
|
486 |
$class = array_map( 'sanitize_html_class', apply_filters( 'display_posts_shortcode_post_class', $class, $post, $listing, $original_atts ) );
|
487 |
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $category_display_text . $excerpt . $content . '</' . $inner_wrapper . '>';
|
488 |
|
489 |
-
// If post is set to private, only show to logged in users
|
490 |
-
if( 'private' == get_post_status( get_the_ID() ) && !current_user_can( 'read_private_posts' ) )
|
491 |
-
$output = '';
|
492 |
-
|
493 |
/**
|
494 |
* Filter the HTML markup for output via the shortcode.
|
495 |
*
|
@@ -670,4 +663,4 @@ function be_display_posts_off( $out, $pairs, $atts ) {
|
|
670 |
*/
|
671 |
$out['display_posts_off'] = apply_filters( 'display_posts_shortcode_inception_override', true );
|
672 |
return $out;
|
673 |
-
}
|
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.7.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.7.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/
|
25 |
|
26 |
/**
|
27 |
* To Customize, use the following filters:
|
28 |
+
* @link https://github.com/billerickson/display-posts-shortcode/wiki#customization-with-filters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
*/
|
30 |
|
31 |
// Create the shortcode
|
37 |
|
38 |
// Pull in shortcode attributes and set defaults
|
39 |
$atts = shortcode_atts( array(
|
40 |
+
'author' => '',
|
41 |
+
'category' => '',
|
42 |
+
'category_display' => '',
|
43 |
+
'category_label' => 'Posted in: ',
|
44 |
+
'content_class' => 'content',
|
45 |
+
'date_format' => '(n/j/Y)',
|
46 |
+
'date' => '',
|
47 |
+
'date_column' => 'post_date',
|
48 |
+
'date_compare' => '=',
|
49 |
+
'date_query_before' => '',
|
50 |
+
'date_query_after' => '',
|
51 |
+
'date_query_column' => '',
|
52 |
+
'date_query_compare' => '',
|
53 |
+
'display_posts_off' => false,
|
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,
|
60 |
+
'image_size' => false,
|
61 |
+
'include_author' => false,
|
62 |
+
'include_content' => false,
|
63 |
+
'include_date' => false,
|
64 |
+
'include_excerpt' => false,
|
65 |
+
'include_title' => true,
|
66 |
+
'meta_key' => '',
|
67 |
+
'meta_value' => '',
|
68 |
+
'no_posts_message' => '',
|
69 |
+
'offset' => 0,
|
70 |
+
'order' => 'DESC',
|
71 |
+
'orderby' => 'date',
|
72 |
+
'post_parent' => false,
|
73 |
+
'post_status' => 'publish',
|
74 |
+
'post_type' => 'post',
|
75 |
+
'posts_per_page' => '10',
|
76 |
+
'tag' => '',
|
77 |
+
'tax_operator' => 'IN',
|
78 |
+
'tax_include_children' => true,
|
79 |
+
'tax_term' => false,
|
80 |
+
'taxonomy' => false,
|
81 |
+
'time' => '',
|
82 |
+
'title' => '',
|
83 |
+
'wrapper' => 'ul',
|
84 |
+
'wrapper_class' => 'display-posts-listing',
|
85 |
+
'wrapper_id' => false,
|
86 |
), $atts, 'display-posts' );
|
87 |
|
88 |
// End early if shortcode should be turned off
|
89 |
if( $atts['display_posts_off'] )
|
90 |
return;
|
91 |
|
92 |
+
$author = sanitize_text_field( $atts['author'] );
|
93 |
+
$category = sanitize_text_field( $atts['category'] );
|
94 |
+
$category_display = 'true' == $atts['category_display'] ? 'category' : sanitize_text_field( $atts['category_display'] );
|
95 |
+
$category_label = sanitize_text_field( $atts['category_label'] );
|
96 |
+
$content_class = array_map( 'sanitize_html_class', ( explode( ' ', $atts['content_class'] ) ) );
|
97 |
+
$date_format = sanitize_text_field( $atts['date_format'] );
|
98 |
+
$date = sanitize_text_field( $atts['date'] );
|
99 |
+
$date_column = sanitize_text_field( $atts['date_column'] );
|
100 |
+
$date_compare = sanitize_text_field( $atts['date_compare'] );
|
101 |
+
$date_query_before = sanitize_text_field( $atts['date_query_before'] );
|
102 |
+
$date_query_after = sanitize_text_field( $atts['date_query_after'] );
|
103 |
+
$date_query_column = sanitize_text_field( $atts['date_query_column'] );
|
104 |
+
$date_query_compare = sanitize_text_field( $atts['date_query_compare'] );
|
105 |
+
$excerpt_length = intval( $atts['excerpt_length'] );
|
106 |
+
$excerpt_more = sanitize_text_field( $atts['excerpt_more'] );
|
107 |
+
$excerpt_more_link = filter_var( $atts['excerpt_more_link'], FILTER_VALIDATE_BOOLEAN );
|
108 |
+
$exclude_current = filter_var( $atts['exclude_current'], FILTER_VALIDATE_BOOLEAN );
|
109 |
+
$id = $atts['id']; // Sanitized later as an array of integers
|
110 |
+
$ignore_sticky_posts = filter_var( $atts['ignore_sticky_posts'], FILTER_VALIDATE_BOOLEAN );
|
111 |
+
$image_size = sanitize_key( $atts['image_size'] );
|
112 |
+
$include_title = filter_var( $atts['include_title'], FILTER_VALIDATE_BOOLEAN );
|
113 |
+
$include_author = filter_var( $atts['include_author'], FILTER_VALIDATE_BOOLEAN );
|
114 |
+
$include_content = filter_var( $atts['include_content'], FILTER_VALIDATE_BOOLEAN );
|
115 |
+
$include_date = filter_var( $atts['include_date'], FILTER_VALIDATE_BOOLEAN );
|
116 |
+
$include_excerpt = filter_var( $atts['include_excerpt'], FILTER_VALIDATE_BOOLEAN );
|
117 |
+
$meta_key = sanitize_text_field( $atts['meta_key'] );
|
118 |
+
$meta_value = sanitize_text_field( $atts['meta_value'] );
|
119 |
+
$no_posts_message = sanitize_text_field( $atts['no_posts_message'] );
|
120 |
+
$offset = intval( $atts['offset'] );
|
121 |
+
$order = sanitize_key( $atts['order'] );
|
122 |
+
$orderby = sanitize_key( $atts['orderby'] );
|
123 |
+
$post_parent = $atts['post_parent']; // Validated later, after check for 'current'
|
124 |
+
$post_status = $atts['post_status']; // Validated later as one of a few values
|
125 |
+
$post_type = sanitize_text_field( $atts['post_type'] );
|
126 |
+
$posts_per_page = intval( $atts['posts_per_page'] );
|
127 |
+
$tag = sanitize_text_field( $atts['tag'] );
|
128 |
+
$tax_operator = $atts['tax_operator']; // Validated later as one of a few values
|
129 |
+
$tax_include_children = filter_var( $atts['tax_include_children'], FILTER_VALIDATE_BOOLEAN );
|
130 |
+
$tax_term = sanitize_text_field( $atts['tax_term'] );
|
131 |
+
$taxonomy = sanitize_key( $atts['taxonomy'] );
|
132 |
+
$time = sanitize_text_field( $atts['time'] );
|
133 |
+
$shortcode_title = sanitize_text_field( $atts['title'] );
|
134 |
+
$wrapper = sanitize_text_field( $atts['wrapper'] );
|
135 |
+
$wrapper_class = array_map( 'sanitize_html_class', ( explode( ' ', $atts['wrapper_class'] ) ) );
|
136 |
|
137 |
if( !empty( $wrapper_class ) )
|
138 |
$wrapper_class = ' class="' . implode( ' ', $wrapper_class ) . '"';
|
295 |
// Validate operator
|
296 |
if( !in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) )
|
297 |
$tax_operator = 'IN';
|
298 |
+
|
299 |
$tax_args = array(
|
300 |
'tax_query' => array(
|
301 |
array(
|
302 |
+
'taxonomy' => $taxonomy,
|
303 |
+
'field' => 'slug',
|
304 |
+
'terms' => $tax_term,
|
305 |
+
'operator' => $tax_operator,
|
306 |
+
'include_children' => $tax_include_children,
|
307 |
)
|
308 |
)
|
309 |
);
|
322 |
$terms = explode( ', ', sanitize_text_field( $original_atts['tax_' . $count . '_term'] ) );
|
323 |
$tax_operator = isset( $original_atts['tax_' . $count . '_operator'] ) ? $original_atts['tax_' . $count . '_operator'] : 'IN';
|
324 |
$tax_operator = in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) ? $tax_operator : 'IN';
|
325 |
+
$tax_include_children = isset( $original_atts['tax_' . $count . '_include_children'] ) ? filter_var( $atts['tax_' . $count . '_include_children'], FILTER_VALIDATE_BOOLEAN ) : true;
|
326 |
|
327 |
$tax_args['tax_query'][] = array(
|
328 |
+
'taxonomy' => $taxonomy,
|
329 |
+
'field' => 'slug',
|
330 |
+
'terms' => $terms,
|
331 |
+
'operator' => $tax_operator,
|
332 |
+
'include_children' => $tax_include_children,
|
333 |
);
|
334 |
|
335 |
$count++;
|
408 |
*
|
409 |
* @param string $author_output HTML markup to display author information.
|
410 |
*/
|
411 |
+
$author = apply_filters( 'display_posts_shortcode_author', ' <span class="author">by ' . get_the_author() . '</span>', $original_atts );
|
412 |
|
413 |
if ( $include_excerpt ) {
|
414 |
|
418 |
$length = $excerpt_length ? $excerpt_length : apply_filters( 'excerpt_length', 55 );
|
419 |
$more = $excerpt_more ? $excerpt_more : apply_filters( 'excerpt_more', '' );
|
420 |
$more = $excerpt_more_link ? ' <a href="' . get_permalink() . '">' . $more . '</a>' : ' ' . $more;
|
421 |
+
|
422 |
+
if( has_excerpt() && apply_filters( 'display_posts_shortcode_full_manual_excerpt', false ) ) {
|
423 |
+
$excerpt = $post->post_excerpt . $more;
|
424 |
+
} elseif( has_excerpt() ) {
|
425 |
+
$excerpt = wp_trim_words( strip_shortcodes( $post->post_excerpt ), $length, $more );
|
426 |
+
} else {
|
427 |
+
$excerpt = wp_trim_words( strip_shortcodes( $post->post_content ), $length, $more );
|
428 |
+
}
|
429 |
|
|
|
430 |
|
431 |
// Use default, can customize with WP filters
|
432 |
} else {
|
483 |
$class = array_map( 'sanitize_html_class', apply_filters( 'display_posts_shortcode_post_class', $class, $post, $listing, $original_atts ) );
|
484 |
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $category_display_text . $excerpt . $content . '</' . $inner_wrapper . '>';
|
485 |
|
|
|
|
|
|
|
|
|
486 |
/**
|
487 |
* Filter the HTML markup for output via the shortcode.
|
488 |
*
|
663 |
*/
|
664 |
$out['display_posts_off'] = apply_filters( 'display_posts_shortcode_inception_override', true );
|
665 |
return $out;
|
666 |
+
}
|
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.
|
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.6.2**
|
34 |
* More improvements to excerpts, see #110
|
35 |
* Added content_class parameter
|
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.7.0
|
8 |
|
9 |
Display a listing of posts using the [display-posts] shortcode
|
10 |
|
30 |
|
31 |
== Changelog ==
|
32 |
|
33 |
+
**Version 2.7.0**
|
34 |
+
* Added support for [Co-Authors Plus Addon](https://github.com/billerickson/dps-coauthor-addon).
|
35 |
+
* Added parameter to exclude children terms in tax queries, [more information](https://github.com/billerickson/display-posts-shortcode/issues/120)
|
36 |
+
* Added a filter to display the full version of manual excerpt, regardless of excerpt_length. [more information](https://github.com/billerickson/display-posts-shortcode/issues/123)
|
37 |
+
* Removed shortcodes from custom excerpts, [more information](https://github.com/billerickson/display-posts-shortcode/issues/113)
|
38 |
+
* Fixed private post visibility, [more information](https://github.com/billerickson/display-posts-shortcode/issues/115)
|
39 |
+
|
40 |
**Version 2.6.2**
|
41 |
* More improvements to excerpts, see #110
|
42 |
* Added content_class parameter
|