Version Description
Download this release
Release Info
Developer | billerickson |
Plugin | Display Posts Shortcode |
Version | 2.3 |
Comparing to | |
See all releases |
Code changes from version 2.2 to 2.3
- display-posts-shortcode.php +50 -32
- readme.txt +10 -2
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 |
*
|
@@ -49,36 +49,42 @@ function be_display_posts_shortcode( $atts ) {
|
|
49 |
|
50 |
// Pull in shortcode attributes and set defaults
|
51 |
$atts = shortcode_atts( array(
|
52 |
-
'author'
|
53 |
-
'category'
|
54 |
-
'date_format'
|
55 |
-
'id'
|
56 |
-
'
|
57 |
-
'
|
58 |
-
'
|
59 |
-
'
|
60 |
-
'
|
61 |
-
'
|
62 |
-
'
|
63 |
-
'
|
64 |
-
'
|
65 |
-
'
|
66 |
-
'
|
67 |
-
'
|
68 |
-
'
|
69 |
-
'
|
70 |
-
'
|
71 |
-
'
|
|
|
|
|
|
|
72 |
), $atts );
|
73 |
|
74 |
$author = sanitize_text_field( $atts['author'] );
|
75 |
$category = sanitize_text_field( $atts['category'] );
|
76 |
$date_format = sanitize_text_field( $atts['date_format'] );
|
77 |
$id = $atts['id']; // Sanitized later as an array of integers
|
|
|
78 |
$image_size = sanitize_key( $atts['image_size'] );
|
79 |
$include_content = (bool)$atts['include_content'];
|
80 |
$include_date = (bool)$atts['include_date'];
|
81 |
$include_excerpt = (bool)$atts['include_excerpt'];
|
|
|
|
|
82 |
$offset = intval( $atts['offset'] );
|
83 |
$order = sanitize_key( $atts['order'] );
|
84 |
$orderby = sanitize_key( $atts['orderby'] );
|
@@ -95,14 +101,22 @@ function be_display_posts_shortcode( $atts ) {
|
|
95 |
|
96 |
// Set up initial query for post
|
97 |
$args = array(
|
98 |
-
'category_name'
|
99 |
-
'order'
|
100 |
-
'orderby'
|
101 |
-
'post_type'
|
102 |
-
'posts_per_page'
|
103 |
-
'tag'
|
104 |
);
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
// If Post IDs
|
107 |
if( $id ) {
|
108 |
$posts_in = array_map( 'intval', explode( ',', $id ) );
|
@@ -204,14 +218,14 @@ function be_display_posts_shortcode( $atts ) {
|
|
204 |
|
205 |
$listing = new WP_Query( apply_filters( 'display_posts_shortcode_args', $args, $original_atts ) );
|
206 |
if ( ! $listing->have_posts() )
|
207 |
-
return apply_filters( 'display_posts_shortcode_no_results',
|
208 |
|
209 |
$inner = '';
|
210 |
while ( $listing->have_posts() ): $listing->the_post(); global $post;
|
211 |
|
212 |
$image = $date = $excerpt = $content = '';
|
213 |
|
214 |
-
$title = '<a class="title" href="' . get_permalink() . '">' . get_the_title() . '</a>';
|
215 |
|
216 |
if ( $image_size && has_post_thumbnail() )
|
217 |
$image = '<a class="image" href="' . get_permalink() . '">' . get_the_post_thumbnail( $post->ID, $image_size ) . '</a> ';
|
@@ -229,12 +243,16 @@ function be_display_posts_shortcode( $atts ) {
|
|
229 |
$class = apply_filters( 'display_posts_shortcode_post_class', $class, $post, $listing );
|
230 |
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $excerpt . $content . '</' . $inner_wrapper . '>';
|
231 |
|
232 |
-
|
|
|
|
|
|
|
|
|
233 |
|
234 |
endwhile; wp_reset_postdata();
|
235 |
|
236 |
-
$open = apply_filters( 'display_posts_shortcode_wrapper_open', '<' . $wrapper . ' class="display-posts-listing">' );
|
237 |
-
$close = apply_filters( 'display_posts_shortcode_wrapper_close', '</' . $wrapper . '>' );
|
238 |
$return = $open . $inner . $close;
|
239 |
|
240 |
return $return;
|
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.3
|
7 |
* Author: Bill Erickson
|
8 |
* Author URI: http://www.billerickson.net
|
9 |
*
|
49 |
|
50 |
// Pull in shortcode attributes and set defaults
|
51 |
$atts = shortcode_atts( array(
|
52 |
+
'author' => '',
|
53 |
+
'category' => '',
|
54 |
+
'date_format' => '(n/j/Y)',
|
55 |
+
'id' => false,
|
56 |
+
'ignore_sticky_posts' => false,
|
57 |
+
'image_size' => false,
|
58 |
+
'include_content' => false,
|
59 |
+
'include_date' => false,
|
60 |
+
'include_excerpt' => false,
|
61 |
+
'meta_key' => '',
|
62 |
+
'no_posts_message' => '',
|
63 |
+
'offset' => 0,
|
64 |
+
'order' => 'DESC',
|
65 |
+
'orderby' => 'date',
|
66 |
+
'post_parent' => false,
|
67 |
+
'post_status' => 'publish',
|
68 |
+
'post_type' => 'post',
|
69 |
+
'posts_per_page' => '10',
|
70 |
+
'tag' => '',
|
71 |
+
'tax_operator' => 'IN',
|
72 |
+
'tax_term' => false,
|
73 |
+
'taxonomy' => false,
|
74 |
+
'wrapper' => 'ul',
|
75 |
), $atts );
|
76 |
|
77 |
$author = sanitize_text_field( $atts['author'] );
|
78 |
$category = sanitize_text_field( $atts['category'] );
|
79 |
$date_format = sanitize_text_field( $atts['date_format'] );
|
80 |
$id = $atts['id']; // Sanitized later as an array of integers
|
81 |
+
$ignore_sticky_posts = (bool) $atts['ignore_sticky_posts'];
|
82 |
$image_size = sanitize_key( $atts['image_size'] );
|
83 |
$include_content = (bool)$atts['include_content'];
|
84 |
$include_date = (bool)$atts['include_date'];
|
85 |
$include_excerpt = (bool)$atts['include_excerpt'];
|
86 |
+
$meta_key = sanitize_text_field( $atts['meta_key'] );
|
87 |
+
$no_posts_message = sanitize_text_field( $atts['no_posts_message'] );
|
88 |
$offset = intval( $atts['offset'] );
|
89 |
$order = sanitize_key( $atts['order'] );
|
90 |
$orderby = sanitize_key( $atts['orderby'] );
|
101 |
|
102 |
// Set up initial query for post
|
103 |
$args = array(
|
104 |
+
'category_name' => $category,
|
105 |
+
'order' => $order,
|
106 |
+
'orderby' => $orderby,
|
107 |
+
'post_type' => explode( ',', $post_type ),
|
108 |
+
'posts_per_page' => $posts_per_page,
|
109 |
+
'tag' => $tag,
|
110 |
);
|
111 |
|
112 |
+
// Ignore Sticky Posts
|
113 |
+
if( $ignore_sticky_posts )
|
114 |
+
$args['ignore_sticky_posts'] = true;
|
115 |
+
|
116 |
+
// Meta key (for ordering)
|
117 |
+
if( !empty( $meta_key ) )
|
118 |
+
$args['meta_key'] = $meta_key;
|
119 |
+
|
120 |
// If Post IDs
|
121 |
if( $id ) {
|
122 |
$posts_in = array_map( 'intval', explode( ',', $id ) );
|
218 |
|
219 |
$listing = new WP_Query( apply_filters( 'display_posts_shortcode_args', $args, $original_atts ) );
|
220 |
if ( ! $listing->have_posts() )
|
221 |
+
return apply_filters( 'display_posts_shortcode_no_results', wpautop( $no_posts_message ) );
|
222 |
|
223 |
$inner = '';
|
224 |
while ( $listing->have_posts() ): $listing->the_post(); global $post;
|
225 |
|
226 |
$image = $date = $excerpt = $content = '';
|
227 |
|
228 |
+
$title = '<a class="title" href="' . apply_filters( 'the_permalink', get_permalink() ) . '">' . apply_filters( 'the_title', get_the_title() ) . '</a>';
|
229 |
|
230 |
if ( $image_size && has_post_thumbnail() )
|
231 |
$image = '<a class="image" href="' . get_permalink() . '">' . get_the_post_thumbnail( $post->ID, $image_size ) . '</a> ';
|
243 |
$class = apply_filters( 'display_posts_shortcode_post_class', $class, $post, $listing );
|
244 |
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $excerpt . $content . '</' . $inner_wrapper . '>';
|
245 |
|
246 |
+
// If post is set to private, only show to logged in users
|
247 |
+
if( 'private' == get_post_status( $post->ID ) && !current_user_can( 'read_private_posts' ) )
|
248 |
+
$output = '';
|
249 |
+
|
250 |
+
$inner .= apply_filters( 'display_posts_shortcode_output', $output, $original_atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class );
|
251 |
|
252 |
endwhile; wp_reset_postdata();
|
253 |
|
254 |
+
$open = apply_filters( 'display_posts_shortcode_wrapper_open', '<' . $wrapper . ' class="display-posts-listing">', $original_atts );
|
255 |
+
$close = apply_filters( 'display_posts_shortcode_wrapper_close', '</' . $wrapper . '>', $original_atts );
|
256 |
$return = $open . $inner . $close;
|
257 |
|
258 |
return $return;
|
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: 3.
|
7 |
-
Stable tag: 2.
|
8 |
|
9 |
Display a listing of posts using the [display-posts] shortcode
|
10 |
|
@@ -27,6 +27,14 @@ See the [WordPress Codex](http://codex.wordpress.org/Class_Reference/WP_Query) f
|
|
27 |
|
28 |
== Changelog ==
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
**Version 2.2**
|
31 |
|
32 |
* Use original attributes for filters
|
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: 3.5
|
7 |
+
Stable tag: 2.3
|
8 |
|
9 |
Display a listing of posts using the [display-posts] shortcode
|
10 |
|
27 |
|
28 |
== Changelog ==
|
29 |
|
30 |
+
**Version 2.3**
|
31 |
+
* Include the shortcode attributes on wrapper filter
|
32 |
+
* Add 'no_posts_message' parameter to specify content displayed if no posts found
|
33 |
+
* Add filters to the title and permalink
|
34 |
+
* Limit private posts to logged in users
|
35 |
+
* Add support for excluding sticky posts
|
36 |
+
* Add support for ordering by meta_key
|
37 |
+
|
38 |
**Version 2.2**
|
39 |
|
40 |
* Use original attributes for filters
|