List category posts - Version 0.60

Version Description

  • Fixes the loop so that other plugins work as if this was a blog or archive post. See issue #156 on Github. Thanks Sophist-UK for this new version :)
Download this release

Release Info

Developer fernandobt
Plugin Icon 128x128 List category posts
Version 0.60
Comparing to
See all releases

Code changes from version 0.59.2 to 0.60

include/lcp-catlist.php CHANGED
@@ -35,11 +35,36 @@ class CatList{
35
  if ( $this->utils->lcp_not_empty('instance') ){
36
  $this->instance = $atts['instance'];
37
  }
38
- //Get the category posts:
 
 
 
 
 
39
  $this->get_lcp_category();
40
  $this->set_lcp_parameters();
41
  }
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  /**
44
  * Order the parameters and query the DB for posts
45
  */
@@ -53,9 +78,9 @@ class CatList{
53
  // http://core.trac.wordpress.org/browser/tags/3.7.1/src/wp-includes/post.php#L1686
54
  $args['posts_per_page'] = $args['numberposts'];
55
 
56
- $query = new WP_Query;
57
- $this->lcp_categories_posts = $query->query($args);
58
- $this->posts_count = $query->found_posts;
59
  remove_all_filters('posts_orderby');
60
  remove_filter('posts_where', array( $this, 'starting_with'));
61
  }
@@ -118,10 +143,6 @@ class CatList{
118
  return $this->lcp_category_id;
119
  }
120
 
121
- public function get_categories_posts(){
122
- return $this->lcp_categories_posts;
123
- }
124
-
125
  /**
126
  * Load category name and link to the category:
127
  */
35
  if ( $this->utils->lcp_not_empty('instance') ){
36
  $this->instance = $atts['instance'];
37
  }
38
+ }
39
+
40
+ /**
41
+ * Determine the categories of posts and execute the WP_query
42
+ */
43
+ public function get_posts() {
44
  $this->get_lcp_category();
45
  $this->set_lcp_parameters();
46
  }
47
 
48
+ /**
49
+ * Save the existing wp_query
50
+ */
51
+ public function save_wp_query() {
52
+ global $wp_query;
53
+ if ( isset($wp_query) ) {
54
+ $this->saved_wp_query = clone $wp_query;
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Restore the previous wp_query
60
+ */
61
+ public function restore_wp_query() {
62
+ global $wp_query;
63
+ if ( isset($this->saved_wp_query) ) {
64
+ $wp_query = clone $this->saved_wp_query;
65
+ }
66
+ }
67
+
68
  /**
69
  * Order the parameters and query the DB for posts
70
  */
78
  // http://core.trac.wordpress.org/browser/tags/3.7.1/src/wp-includes/post.php#L1686
79
  $args['posts_per_page'] = $args['numberposts'];
80
 
81
+ query_posts($args);
82
+ global $wp_query;
83
+ $this->posts_count = $wp_query->found_posts;
84
  remove_all_filters('posts_orderby');
85
  remove_filter('posts_where', array( $this, 'starting_with'));
86
  }
143
  return $this->lcp_category_id;
144
  }
145
 
 
 
 
 
146
  /**
147
  * Load category name and link to the category:
148
  */
include/lcp-catlistdisplayer.php CHANGED
@@ -19,10 +19,16 @@ class CatListDisplayer {
19
  public function __construct($atts) {
20
  $this->params = $atts;
21
  $this->catlist = new CatList($atts);
22
- $this->select_template();
 
23
  }
24
 
25
  public function display(){
 
 
 
 
 
26
  return $this->lcp_output;
27
  }
28
 
@@ -119,21 +125,21 @@ class CatListDisplayer {
119
  $inner_tag = ( ($tag == 'ul') || ($tag == 'ol') ) ? 'li' : 'p';
120
 
121
  //Posts loop
122
- foreach ($this->catlist->get_categories_posts() as $single) :
123
- if ( !post_password_required($single) ||
124
- ( post_password_required($single) && (
 
125
  isset($this->params['show_protected']) &&
126
  $this->params['show_protected'] == 'yes' ) )):
127
- $this->lcp_output .= $this->lcp_build_post($single, $inner_tag);
128
  endif;
129
- endforeach;
130
 
131
  if ( ($this->catlist->get_posts_count() == 0) &&
132
  ($this->params["no_posts_text"] != '') ) {
133
  $this->lcp_output .= $this->params["no_posts_text"];
134
  }
135
 
136
-
137
  //Close wrapper tag
138
  $this->lcp_output .= '</' . $tag . '>';
139
 
@@ -219,14 +225,11 @@ class CatListDisplayer {
219
  * @return string
220
  */
221
  private function lcp_build_post($single, $tag){
222
- global $post;
223
 
224
  $class ='';
225
-
226
- if ( is_object($post) && is_object($single) && $post->ID == $single->ID ){
227
- $class = " class = current ";
228
  }
229
-
230
  $lcp_display_output = '<'. $tag . $class . '>';
231
 
232
  if ( empty($this->params['no_post_titles']) || !empty($this->params['no_post_titles']) && $this->params['no_post_titles'] !== 'yes' ) {
19
  public function __construct($atts) {
20
  $this->params = $atts;
21
  $this->catlist = new CatList($atts);
22
+ global $post;
23
+ $this->parent = $post;
24
  }
25
 
26
  public function display(){
27
+ $this->catlist->save_wp_query();
28
+ $this->catlist->get_posts();
29
+ $this->select_template();
30
+ $this->catlist->restore_wp_query();
31
+ wp_reset_query();
32
  return $this->lcp_output;
33
  }
34
 
125
  $inner_tag = ( ($tag == 'ul') || ($tag == 'ol') ) ? 'li' : 'p';
126
 
127
  //Posts loop
128
+ global $post;
129
+ while ( have_posts() ) : the_post();
130
+ if ( !post_password_required($post) ||
131
+ ( post_password_required($post) && (
132
  isset($this->params['show_protected']) &&
133
  $this->params['show_protected'] == 'yes' ) )):
134
+ $this->lcp_output .= $this->lcp_build_post($post, $inner_tag);
135
  endif;
136
+ endwhile;
137
 
138
  if ( ($this->catlist->get_posts_count() == 0) &&
139
  ($this->params["no_posts_text"] != '') ) {
140
  $this->lcp_output .= $this->params["no_posts_text"];
141
  }
142
 
 
143
  //Close wrapper tag
144
  $this->lcp_output .= '</' . $tag . '>';
145
 
225
  * @return string
226
  */
227
  private function lcp_build_post($single, $tag){
 
228
 
229
  $class ='';
230
+ if ( is_object($this->parent) && is_object($single) && $this->parent->ID == $single->ID ){
231
+ $class = ' class="current" ';
 
232
  }
 
233
  $lcp_display_output = '<'. $tag . $class . '>';
234
 
235
  if ( empty($this->params['no_post_titles']) || !empty($this->params['no_post_titles']) && $this->params['no_post_titles'] !== 'yes' ) {
list_cat_posts.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: List category posts
4
  Plugin URI: https://github.com/picandocodigo/List-Category-Posts
5
  Description: List Category Posts allows you to list posts by category in a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, the number of posts to display and many more parameters. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
6
- Version: 0.59.2
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
3
  Plugin Name: List category posts
4
  Plugin URI: https://github.com/picandocodigo/List-Category-Posts
5
  Description: List Category Posts allows you to list posts by category in a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, the number of posts to display and many more parameters. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
6
+ Version: 0.60
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: fernandobt
3
  Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
- Tested up to: 4.2
7
- Stable tag: 0.59.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -451,6 +451,13 @@ Template system has changed. Custom templates should be stored in WordPress them
451
 
452
  == Changelog ==
453
 
 
 
 
 
 
 
 
454
  = 0.59.2 =
455
 
456
  * Tested with WordPress 4.2
3
  Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
+ Tested up to: 4.2.1
7
+ Stable tag: 0.60
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
451
 
452
  == Changelog ==
453
 
454
+ = 0.60 =
455
+
456
+ * Fixes the loop so that other plugins work as if this was a blog or archive post.
457
+ See [issue
458
+ #156](https://github.com/picandocodigo/List-Category-Posts/issues/156)
459
+ on Github. Thanks Sophist-UK for this new version :)
460
+
461
  = 0.59.2 =
462
 
463
  * Tested with WordPress 4.2