Version Description
- Adds pagination. Check Pagination on Other
notes
to learn how to use it.
- Adds "How to display thumbnails next to title" to the FAQ.
- Adds a Vagrant box for developers to be able to start coding with no effort :)
Download this release
Release Info
Developer | fernandobt |
Plugin | List category posts |
Version | 0.38 |
Comparing to | |
See all releases |
Code changes from version 0.37 to 0.38
- include/CatList.php +38 -1
- include/CatListDisplayer.php +55 -0
- lcp_paginator.css +6 -0
- list_cat_posts.php +19 -4
- readme.txt +61 -3
include/CatList.php
CHANGED
@@ -10,6 +10,9 @@ class CatList{
|
|
10 |
private $lcp_category_id = 0;
|
11 |
private $category_param;
|
12 |
private $exclude;
|
|
|
|
|
|
|
13 |
|
14 |
/**
|
15 |
* Constructor gets the shortcode attributes as parameter
|
@@ -18,6 +21,9 @@ class CatList{
|
|
18 |
public function __construct($atts) {
|
19 |
$this->params = $atts;
|
20 |
|
|
|
|
|
|
|
21 |
//Get the category posts:
|
22 |
$this->get_lcp_category();
|
23 |
$this->set_lcp_parameters();
|
@@ -124,7 +130,22 @@ class CatList{
|
|
124 |
$args['meta_key'] = $this->params['customfield_orderby'];
|
125 |
endif;
|
126 |
|
127 |
-
$this->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
}
|
129 |
|
130 |
private function lcp_not_empty($param){
|
@@ -322,6 +343,22 @@ class CatList{
|
|
322 |
}
|
323 |
|
324 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
|
326 |
public function get_date_to_show($single){
|
327 |
if ($this->params['date']=='yes'):
|
10 |
private $lcp_category_id = 0;
|
11 |
private $category_param;
|
12 |
private $exclude;
|
13 |
+
private $page = 1;
|
14 |
+
private $posts_count = 0;
|
15 |
+
private $instance = 0;
|
16 |
|
17 |
/**
|
18 |
* Constructor gets the shortcode attributes as parameter
|
21 |
public function __construct($atts) {
|
22 |
$this->params = $atts;
|
23 |
|
24 |
+
if ($this->lcp_not_empty('instance')){
|
25 |
+
$this->instance = $atts['instance'];
|
26 |
+
}
|
27 |
//Get the category posts:
|
28 |
$this->get_lcp_category();
|
29 |
$this->set_lcp_parameters();
|
130 |
$args['meta_key'] = $this->params['customfield_orderby'];
|
131 |
endif;
|
132 |
|
133 |
+
if ( $this->lcp_not_empty('pagination')):
|
134 |
+
if( preg_match('/lcp_page' . preg_quote($this->instance) .
|
135 |
+
'=([0-9]+)/i', $_SERVER['QUERY_STRING'], $match) ):
|
136 |
+
$this->page = $match[1];
|
137 |
+
$offset = ($this->page - 1) * $this->params['numberposts'];
|
138 |
+
$args = array_merge($args, array('offset' => $offset));
|
139 |
+
endif;
|
140 |
+
endif;
|
141 |
+
|
142 |
+
// for WP_Query compatibility
|
143 |
+
// http://core.trac.wordpress.org/browser/tags/3.7.1/src/wp-includes/post.php#L1686
|
144 |
+
$args['posts_per_page'] = $args['numberposts'];
|
145 |
+
|
146 |
+
$query = new WP_Query;
|
147 |
+
$this->lcp_categories_posts = $query->query($args);
|
148 |
+
$this->posts_count = $query->found_posts;
|
149 |
}
|
150 |
|
151 |
private function lcp_not_empty($param){
|
343 |
}
|
344 |
|
345 |
|
346 |
+
/** Pagination **/
|
347 |
+
public function get_page(){
|
348 |
+
return $this->page;
|
349 |
+
}
|
350 |
+
|
351 |
+
public function get_posts_count(){
|
352 |
+
return $this->posts_count;
|
353 |
+
}
|
354 |
+
|
355 |
+
public function get_number_posts(){
|
356 |
+
return $this->params['numberposts'];
|
357 |
+
}
|
358 |
+
|
359 |
+
public function get_instance(){
|
360 |
+
return $this->instance;
|
361 |
+
}
|
362 |
|
363 |
public function get_date_to_show($single){
|
364 |
if ($this->params['date']=='yes'):
|
include/CatListDisplayer.php
CHANGED
@@ -75,9 +75,17 @@ class CatListDisplayer {
|
|
75 |
if (isset($this->params['class'])):
|
76 |
$this->lcp_output .= ' class="' . $this->params['class'] . '"';
|
77 |
endif;
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
$this->lcp_output .= '>';
|
79 |
$inner_tag = ($tag == 'ul') ? 'li' : 'p';
|
80 |
|
|
|
|
|
81 |
//Posts loop
|
82 |
foreach ($this->catlist->get_categories_posts() as $single) :
|
83 |
if ( !post_password_required($single) ) :
|
@@ -101,6 +109,53 @@ class CatListDisplayer {
|
|
101 |
$this->lcp_output .= $this->get_morelink();
|
102 |
endif;
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
|
106 |
/**
|
75 |
if (isset($this->params['class'])):
|
76 |
$this->lcp_output .= ' class="' . $this->params['class'] . '"';
|
77 |
endif;
|
78 |
+
|
79 |
+
//Give id to wrapper tag
|
80 |
+
if (isset($this->params['instance'])){
|
81 |
+
$this->lcp_output .= ' id=lcp_instance_' . $this->params['instance'];
|
82 |
+
}
|
83 |
+
|
84 |
$this->lcp_output .= '>';
|
85 |
$inner_tag = ($tag == 'ul') ? 'li' : 'p';
|
86 |
|
87 |
+
|
88 |
+
|
89 |
//Posts loop
|
90 |
foreach ($this->catlist->get_categories_posts() as $single) :
|
91 |
if ( !post_password_required($single) ) :
|
109 |
$this->lcp_output .= $this->get_morelink();
|
110 |
endif;
|
111 |
|
112 |
+
if (!empty($this->params['pagination']) && $this->params['pagination'] == "yes"):
|
113 |
+
$lcp_paginator = '';
|
114 |
+
$pages_count = ceil (
|
115 |
+
$this->catlist->get_posts_count() / $this->catlist->get_number_posts()
|
116 |
+
);
|
117 |
+
for($i = 1; $i <= $pages_count; $i++){
|
118 |
+
$lcp_paginator .= $this->lcp_page_link($i, true);
|
119 |
+
}
|
120 |
+
|
121 |
+
$this->lcp_output .= "<ul class='lcp_paginator'>";
|
122 |
+
|
123 |
+
// Add "Previous" link
|
124 |
+
if ($this->catlist->get_page() > 1){
|
125 |
+
$this->lcp_output .= $this->lcp_page_link( intval($this->catlist->get_page()) - 1, "<<" );
|
126 |
+
}
|
127 |
+
|
128 |
+
$this->lcp_output .= $lcp_paginator;
|
129 |
+
// Add "Next" link
|
130 |
+
if ($this->catlist->get_page() < $pages_count){
|
131 |
+
$this->lcp_output .= $this->lcp_page_link( intval($this->catlist->get_page()) + 1, ">>");
|
132 |
+
}
|
133 |
+
$this->lcp_output .= "</ul>";
|
134 |
+
|
135 |
+
endif;
|
136 |
+
}
|
137 |
+
|
138 |
+
private function lcp_page_link($page, $char = nil){
|
139 |
+
$current_page = $this->catlist->get_page();
|
140 |
+
$link = '';
|
141 |
+
|
142 |
+
if ($page == $current_page){
|
143 |
+
$link = "<li>$current_page</li>";
|
144 |
+
} else {
|
145 |
+
$amp = ( strpos($_SERVER["REQUEST_URI"], "?") ) ? "&" : "";
|
146 |
+
$pattern = "/[&|?]?lcp_page" . preg_quote($this->catlist->get_instance()) . "=([0-9]+)/";
|
147 |
+
$query = preg_replace($pattern, '', $_SERVER['QUERY_STRING']);
|
148 |
+
|
149 |
+
$url = strtok($_SERVER["REQUEST_URI"],'?');
|
150 |
+
|
151 |
+
$page_link = "http://$_SERVER[HTTP_HOST]$url?$query" .
|
152 |
+
$amp . "lcp_page" . $this->catlist->get_instance() . "=". $page .
|
153 |
+
"#lcp_instance_" . $this->catlist->get_instance();
|
154 |
+
$link .= "<li><a href='$page_link' title='$page'>";
|
155 |
+
($char != nil) ? ($link .= $char) : ($link .= $page);
|
156 |
+
$link .= "</a></li>";
|
157 |
+
}
|
158 |
+
return $link;
|
159 |
}
|
160 |
|
161 |
/**
|
lcp_paginator.css
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.lcp_paginator li{
|
2 |
+
display: inline-block;
|
3 |
+
border: 1px solid;
|
4 |
+
padding: 0 5px;
|
5 |
+
margin: 2px;
|
6 |
+
}
|
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 from a category into 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, and the number of posts to display. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
|
6 |
-
Version: 0.
|
7 |
Author: Fernando Briano
|
8 |
Author URI: http://picandocodigo.net/
|
9 |
|
@@ -99,9 +99,13 @@ class ListCategoryPosts{
|
|
99 |
'year' => '',
|
100 |
'monthnum' => '',
|
101 |
'search' => '',
|
102 |
-
'link_target' => ''
|
|
|
|
|
103 |
), $atts);
|
104 |
-
|
|
|
|
|
105 |
$catlist_displayer = new CatListDisplayer($atts);
|
106 |
return $catlist_displayer->display();
|
107 |
}
|
@@ -127,9 +131,20 @@ function lpc_meta($links, $file) {
|
|
127 |
|
128 |
add_filter( 'plugin_row_meta', 'lpc_meta', 10, 2 );
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
/**
|
131 |
* TO-DO:
|
132 |
-
|
133 |
- Pagination * DONE - Need to add "page" text
|
134 |
- Add Older Posts at bottom of List Category Post page
|
135 |
- Simpler template system
|
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 from a category into 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, and the number of posts to display. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
|
6 |
+
Version: 0.38
|
7 |
Author: Fernando Briano
|
8 |
Author URI: http://picandocodigo.net/
|
9 |
|
99 |
'year' => '',
|
100 |
'monthnum' => '',
|
101 |
'search' => '',
|
102 |
+
'link_target' => '',
|
103 |
+
'pagination' => 'no',
|
104 |
+
'instance' => '0'
|
105 |
), $atts);
|
106 |
+
if( $atts['pagination'] == 'yes'){
|
107 |
+
lcp_pagination_css();
|
108 |
+
}
|
109 |
$catlist_displayer = new CatListDisplayer($atts);
|
110 |
return $catlist_displayer->display();
|
111 |
}
|
131 |
|
132 |
add_filter( 'plugin_row_meta', 'lpc_meta', 10, 2 );
|
133 |
|
134 |
+
function lcp_pagination_css(){
|
135 |
+
if ( @file_exists( get_stylesheet_directory() . '/lcp_paginator.css' ) ):
|
136 |
+
$css_file = get_stylesheet_directory_uri() . '/lcp_paginator.css';
|
137 |
+
elseif ( @file_exists( get_template_directory() . '/lcp_paginator.css' ) ):
|
138 |
+
$css_file = get_template_directory_uri() . '/lcp_paginator.css';
|
139 |
+
else:
|
140 |
+
$css_file = WP_PLUGIN_URL . '/' . basename( __DIR__ ) . '/lcp_paginator.css';
|
141 |
+
endif;
|
142 |
+
|
143 |
+
wp_enqueue_style( 'lcp_paginator', $css_file, false, '2.70' );
|
144 |
+
}
|
145 |
+
|
146 |
/**
|
147 |
* TO-DO:
|
|
|
148 |
- Pagination * DONE - Need to add "page" text
|
149 |
- Add Older Posts at bottom of List Category Post page
|
150 |
- Simpler template system
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts
|
|
4 |
Tags: list, categories, posts, cms
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 3.7.1
|
7 |
-
Stable tag: 0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -74,6 +74,35 @@ When using List Category Posts whithout a category id, name or slug, it will pos
|
|
74 |
* **include** posts from several categories with **OR** relationship, posts that belong to any of the listed categories: `[catlist id=17,24,32]` - `[catlist name=sega,nintendo]`.
|
75 |
* **exclude** a category with the minus sign (-): `[catlist id=11,-32,16]`, `[catlist id=1+2-3]`. **Important**: When using the *and* relationship, the order must be categories you want to include first, and exclude after. So `[catlist id=1+2-3]` will work, but `[catlist id=1+2-3+4]` won't.
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
==Other parameters==
|
79 |
|
@@ -106,7 +135,7 @@ When using List Category Posts whithout a category id, name or slug, it will pos
|
|
106 |
|
107 |
* **numberposts** - Number of posts to return. Set to 0 to use the max number of posts per page. Set to -1 to remove the limit. Default: 5. Ex: `[catlist name=mycategory numberposts=10]`
|
108 |
|
109 |
-
* **monthnum** and **year** - List posts from a certain year or month. You can use these together or independently. Example: `[catlist year=2015]` will list posts from the year 2015. `[catlist monthnum=8]` will list posts published in August of every year. `[catlist year=2012
|
110 |
|
111 |
* **search** - List posts that match a search term. `[catlist search="The Cake is a lie"]`
|
112 |
|
@@ -226,6 +255,27 @@ This is true since version 0.18. If you're still using PHP 4 on your webhost, yo
|
|
226 |
Please check:
|
227 |
http://wordpress.stackexchange.com/questions/9338/list-category-posts-plugin-upgrade-fails-fatal-error/9340#9340
|
228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
**How to not display the title**
|
230 |
|
231 |
You have to add a CSS class to the title with the `title_class` parameter. Then edit the title_class class in your theme's CSS file. Something like this:
|
@@ -278,8 +328,16 @@ Template system has changed. Custom templates should be stored in WordPress them
|
|
278 |
|
279 |
== Changelog ==
|
280 |
|
281 |
-
= 0.
|
282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
* Supports `more` tag. If there's a <!--more--> tag in the post, then it will behave just as WordPress does: only show the content previous to the more tag.
|
284 |
* Fixes YouTube thumbnails: Includes "embed" urls for youtube video
|
285 |
thumbnails, makes correct img tag when using CSS class.
|
4 |
Tags: list, categories, posts, cms
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 3.7.1
|
7 |
+
Stable tag: 0.38
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
74 |
* **include** posts from several categories with **OR** relationship, posts that belong to any of the listed categories: `[catlist id=17,24,32]` - `[catlist name=sega,nintendo]`.
|
75 |
* **exclude** a category with the minus sign (-): `[catlist id=11,-32,16]`, `[catlist id=1+2-3]`. **Important**: When using the *and* relationship, the order must be categories you want to include first, and exclude after. So `[catlist id=1+2-3]` will work, but `[catlist id=1+2-3+4]` won't.
|
76 |
|
77 |
+
==Pagination==
|
78 |
+
|
79 |
+
To use pagination, you need to set the following parameters:
|
80 |
+
|
81 |
+
* **pagination** set it to yes.
|
82 |
+
|
83 |
+
* **numberposts** - Posts per page are set with the `numberposts` parameter.
|
84 |
+
|
85 |
+
* **instance** (only necessary when using the shortcode with
|
86 |
+
pagination more than once in the same page/post) - a number or
|
87 |
+
name to identify the instance where you are using pagination.
|
88 |
+
Since you can use the shortcode several times in the same page or
|
89 |
+
post, you need to identify the instance so that you paginate only
|
90 |
+
that instance.
|
91 |
+
|
92 |
+
|
93 |
+
Example:
|
94 |
+
|
95 |
+
`[catlist id=3 numberposts=5 pagination=yes instance=1]`
|
96 |
+
|
97 |
+
`[catlist id=5 numberposts=15 pagination=yes instance=2]`
|
98 |
+
|
99 |
+
==Changing the pagination CSS==
|
100 |
+
|
101 |
+
If you want to customize the way the pagination is displayed, you can
|
102 |
+
copy the `lcp_paginator.css` file from the plugin's directory to your
|
103 |
+
theme's directory and customize it. Do not customize the file on the
|
104 |
+
plugin's directory since this file will be overwritten every time you
|
105 |
+
update the plugin.
|
106 |
|
107 |
==Other parameters==
|
108 |
|
135 |
|
136 |
* **numberposts** - Number of posts to return. Set to 0 to use the max number of posts per page. Set to -1 to remove the limit. Default: 5. Ex: `[catlist name=mycategory numberposts=10]`
|
137 |
|
138 |
+
* **monthnum** and **year** - List posts from a certain year or month. You can use these together or independently. Example: `[catlist year=2015]` will list posts from the year 2015. `[catlist monthnum=8]` will list posts published in August of every year. `[catlist year=2012 monthnum=12]` will list posts from December 2012.
|
139 |
|
140 |
* **search** - List posts that match a search term. `[catlist search="The Cake is a lie"]`
|
141 |
|
255 |
Please check:
|
256 |
http://wordpress.stackexchange.com/questions/9338/list-category-posts-plugin-upgrade-fails-fatal-error/9340#9340
|
257 |
|
258 |
+
**How do I display the Thumbnail next to the title?**
|
259 |
+
|
260 |
+
To see the thumbnail next to the title, you can add a class to it like
|
261 |
+
this:
|
262 |
+
|
263 |
+
`[catlist id=1 thumbnail=yes thumbnail_class=lcp_thumbnail]`
|
264 |
+
|
265 |
+
Then in your theme's stylesheet add this code:
|
266 |
+
|
267 |
+
`.lcp_thumbnail{
|
268 |
+
float: left;
|
269 |
+
}
|
270 |
+
|
271 |
+
.lcp_catlist li{
|
272 |
+
clear: both;
|
273 |
+
}`
|
274 |
+
|
275 |
+
If you want the thumbnail to the right, just change the `float: left`
|
276 |
+
attribute to `float: right`.
|
277 |
+
|
278 |
+
|
279 |
**How to not display the title**
|
280 |
|
281 |
You have to add a CSS class to the title with the `title_class` parameter. Then edit the title_class class in your theme's CSS file. Something like this:
|
328 |
|
329 |
== Changelog ==
|
330 |
|
331 |
+
= 0.38 =
|
332 |
|
333 |
+
* Adds pagination. Check **Pagination** on [Other
|
334 |
+
notes](http://wordpress.org/extend/plugins/list-category-posts/other_notes/)
|
335 |
+
to learn how to use it.
|
336 |
+
* Adds "How to display thumbnails next to title" to the FAQ.
|
337 |
+
* Adds a Vagrant box for developers to be able to start coding with
|
338 |
+
no effort :)
|
339 |
+
|
340 |
+
= 0.37 =
|
341 |
* Supports `more` tag. If there's a <!--more--> tag in the post, then it will behave just as WordPress does: only show the content previous to the more tag.
|
342 |
* Fixes YouTube thumbnails: Includes "embed" urls for youtube video
|
343 |
thumbnails, makes correct img tag when using CSS class.
|