Display Posts Shortcode - Version 2.2

Version Description

Download this release

Release Info

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

Code changes from version 2.1 to 2.2

Files changed (2) hide show
  1. display-posts-shortcode.php +50 -6
  2. readme.txt +10 -3
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.1
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.1
19
  * @author Bill Erickson <bill@billerickson.net>
20
  * @copyright Copyright (c) 2011, Bill Erickson
21
  * @link http://www.billerickson.net/shortcode-to-display-posts/
@@ -44,6 +44,9 @@
44
  add_shortcode( 'display-posts', 'be_display_posts_shortcode' );
45
  function be_display_posts_shortcode( $atts ) {
46
 
 
 
 
47
  // Pull in shortcode attributes and set defaults
48
  $atts = shortcode_atts( array(
49
  'author' => '',
@@ -51,6 +54,7 @@ function be_display_posts_shortcode( $atts ) {
51
  'date_format' => '(n/j/Y)',
52
  'id' => false,
53
  'image_size' => false,
 
54
  'include_date' => false,
55
  'include_excerpt' => false,
56
  'offset' => 0,
@@ -72,6 +76,7 @@ function be_display_posts_shortcode( $atts ) {
72
  $date_format = sanitize_text_field( $atts['date_format'] );
73
  $id = $atts['id']; // Sanitized later as an array of integers
74
  $image_size = sanitize_key( $atts['image_size'] );
 
75
  $include_date = (bool)$atts['include_date'];
76
  $include_excerpt = (bool)$atts['include_excerpt'];
77
  $offset = intval( $atts['offset'] );
@@ -143,6 +148,40 @@ function be_display_posts_shortcode( $atts ) {
143
  )
144
  )
145
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  $args = array_merge( $args, $tax_args );
147
  }
148
 
@@ -163,14 +202,14 @@ function be_display_posts_shortcode( $atts ) {
163
  $inner_wrapper = 'div' == $wrapper ? 'div' : 'li';
164
 
165
 
166
- $listing = new WP_Query( apply_filters( 'display_posts_shortcode_args', $args, $atts ) );
167
  if ( ! $listing->have_posts() )
168
  return apply_filters( 'display_posts_shortcode_no_results', false );
169
 
170
  $inner = '';
171
  while ( $listing->have_posts() ): $listing->the_post(); global $post;
172
 
173
- $image = $date = $excerpt = '';
174
 
175
  $title = '<a class="title" href="' . get_permalink() . '">' . get_the_title() . '</a>';
176
 
@@ -182,10 +221,15 @@ function be_display_posts_shortcode( $atts ) {
182
 
183
  if ( $include_excerpt )
184
  $excerpt = ' <span class="excerpt-dash">-</span> <span class="excerpt">' . get_the_excerpt() . '</span>';
 
 
 
185
 
186
- $output = '<' . $inner_wrapper . ' class="listing-item">' . $image . $title . $date . $excerpt . '</' . $inner_wrapper . '>';
 
 
187
 
188
- $inner .= apply_filters( 'display_posts_shortcode_output', $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper );
189
 
190
  endwhile; wp_reset_postdata();
191
 
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.2
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.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/
44
  add_shortcode( 'display-posts', 'be_display_posts_shortcode' );
45
  function be_display_posts_shortcode( $atts ) {
46
 
47
+ // Original Attributes, for filters
48
+ $original_atts = $atts;
49
+
50
  // Pull in shortcode attributes and set defaults
51
  $atts = shortcode_atts( array(
52
  'author' => '',
54
  'date_format' => '(n/j/Y)',
55
  'id' => false,
56
  'image_size' => false,
57
+ 'include_content' => false,
58
  'include_date' => false,
59
  'include_excerpt' => false,
60
  'offset' => 0,
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'] );
148
  )
149
  )
150
  );
151
+
152
+ // Check for multiple taxonomy queries
153
+ $count = 2;
154
+ $more_tax_queries = false;
155
+ while(
156
+ isset( $original_atts['taxonomy_' . $count] ) && !empty( $original_atts['taxonomy_' . $count] ) &&
157
+ isset( $original_atts['tax_' . $count . '_term'] ) && !empty( $original_atts['tax_' . $count . '_term'] )
158
+ ):
159
+
160
+ // Sanitize values
161
+ $more_tax_queries = true;
162
+ $taxonomy = sanitize_key( $original_atts['taxonomy_' . $count] );
163
+ $terms = explode( ', ', sanitize_text_field( $original_atts['tax_' . $count . '_term'] ) );
164
+ $tax_operator = isset( $original_atts['tax_' . $count . '_operator'] ) ? $original_atts['tax_' . $count . '_operator'] : 'IN';
165
+ $tax_operator = in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) ? $tax_operator : 'IN';
166
+
167
+ $tax_args['tax_query'][] = array(
168
+ 'taxonomy' => $taxonomy,
169
+ 'field' => 'slug',
170
+ 'terms' => $terms,
171
+ 'operator' => $tax_operator
172
+ );
173
+
174
+ $count++;
175
+
176
+ endwhile;
177
+
178
+ if( $more_tax_queries ):
179
+ $tax_relation = 'AND';
180
+ if( isset( $original_atts['tax_relation'] ) && in_array( $original_atts['tax_relation'], array( 'AND', 'OR' ) ) )
181
+ $tax_relation = $original_atts['tax_relation'];
182
+ $args['tax_query']['relation'] = $tax_relation;
183
+ endif;
184
+
185
  $args = array_merge( $args, $tax_args );
186
  }
187
 
202
  $inner_wrapper = 'div' == $wrapper ? 'div' : 'li';
203
 
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', false );
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
 
221
 
222
  if ( $include_excerpt )
223
  $excerpt = ' <span class="excerpt-dash">-</span> <span class="excerpt">' . get_the_excerpt() . '</span>';
224
+
225
+ if( $include_content )
226
+ $content = '<div class="content">' . apply_filters( 'the_content', get_the_content() ) . '</div>';
227
 
228
+ $class = array( 'listing-item' );
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
+ $inner .= apply_filters( 'display_posts_shortcode_output', $output, $original_atts, $image, $title, $date, $excerpt, $inner_wrapper, $content );
233
 
234
  endwhile; wp_reset_postdata();
235
 
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: 3.4.2
7
- Stable tag: 2.1
8
 
9
  Display a listing of posts using the [display-posts] shortcode
10
 
@@ -27,11 +27,18 @@ See the [WordPress Codex](http://codex.wordpress.org/Class_Reference/WP_Query) f
27
 
28
  == Changelog ==
29
 
30
- **Veresion 2.1**
 
 
 
 
 
 
 
31
 
32
  * Add support for post status
33
  * Add support for post author
34
- * Add support for post author
35
 
36
  **Version 2.0**
37
 
4
  Tags: shortcode, pages, posts, page, query, display, list
5
  Requires at least: 3.0
6
  Tested up to: 3.4.2
7
+ Stable tag: 2.2
8
 
9
  Display a listing of posts using the [display-posts] shortcode
10
 
27
 
28
  == Changelog ==
29
 
30
+ **Version 2.2**
31
+
32
+ * Use original attributes for filters
33
+ * Add support for multiple taxonomy queries
34
+ * Add filter for post classes
35
+ * Add support for post content in the post loop
36
+
37
+ **Version 2.1**
38
 
39
  * Add support for post status
40
  * Add support for post author
41
+ * Add support for post offset
42
 
43
  **Version 2.0**
44