PluginProbe
Page-list / 1.8
Page-list v1.8
6.3 6.1 6.2 6.0 trunk 1.0.0 1.2.0 1.3.0 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 All 47 releases
page-list / page-list.php

page-list.php in Page-list 1.8, at page-list.php

342 lines 10.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Page-list
4 Plugin URI: http://web-profile.com.ua/wordpress/plugins/page-list/
5 Description: Show list of pages with [pagelist], [subpages], [siblings] and [pagelist_ext] shortcodes.
6 Version: 1.8
7 Author: webvitaly
8 Author Email: webvitaly(at)gmail.com
9 Author URI: http://web-profile.com.ua/wordpress/
10
11 Future features:
12 - exclude_by_alias;
13 - exclude_front_page;
14 - exclude_post_page;
15 */
16
17 add_action('wp_print_styles', 'page_list_add_stylesheet');
18 function page_list_add_stylesheet() {
19 wp_enqueue_style( 'page-list-style', plugins_url( '/css/page-list.css', __FILE__ ), false, '1.8', 'all' );
20 }
21
22 if ( !function_exists('pagelist_norm_params') ) {
23 function pagelist_norm_params( $str ) {
24 global $post;
25 $new_str = $str;
26 $new_str = str_replace('this', $post->ID, $new_str); // exclude this page
27 $new_str = str_replace('current', $post->ID, $new_str); // exclude current page
28 $new_str = str_replace('curent', $post->ID, $new_str); // exclude curent page with mistake
29 $new_str = str_replace('parent', $post->post_parent, $new_str); // exclude parent page
30 return $new_str;
31 }
32 }
33
34 if ( !function_exists('pagelist_shortcode') ) {
35 function pagelist_shortcode( $atts ) {
36 global $post;
37 $return = '';
38 extract( shortcode_atts( array(
39 'depth' => '0',
40 'child_of' => '0',
41 'exclude' => '0',
42 'exclude_tree' => '',
43 'include' => '0',
44 'title_li' => '',
45 'number' => '',
46 'offset' => '',
47 'meta_key' => '',
48 'meta_value' => '',
49 'show_date' => '',
50 'sort_column' => 'menu_order, post_title',
51 'sort_order' => 'ASC',
52 'link_before' => '',
53 'link_after' => '',
54 'class' => ''
55 ), $atts ) );
56
57 $page_list_args = array(
58 'depth' => $depth,
59 'child_of' => pagelist_norm_params($child_of),
60 'exclude' => pagelist_norm_params($exclude),
61 'exclude_tree' => $exclude_tree,
62 'include' => $include,
63 'title_li' => $title_li,
64 'number' => $number,
65 'offset' => $offset,
66 'meta_key' => $meta_key,
67 'meta_value' => $meta_value,
68 'show_date' => $show_date,
69 'date_format' => get_option('date_format'),
70 'echo' => 0,
71 'authors' => '',
72 'sort_column' => $sort_column,
73 'sort_order' => $sort_order,
74 'link_before' => $link_before,
75 'link_after' => $link_after,
76 'walker' => ''
77 );
78 $list_pages = wp_list_pages( $page_list_args );
79
80 if ($list_pages) {
81 $return = "\n".'<!-- powered by Page-list plugin ver.1.8 (wordpress.org/extend/plugins/page-list/) -->'."\n";
82 $return .= '<ul class="page-list '.$class.'">'."\n".$list_pages."\n".'</ul>';
83 }else{
84 $return = '';
85 }
86 return $return;
87 }
88 add_shortcode( 'pagelist', 'pagelist_shortcode' );
89 add_shortcode( 'page_list', 'pagelist_shortcode' );
90 add_shortcode( 'page-list', 'pagelist_shortcode' ); // not good (Shortcode names should be all lowercase and use all letters, but numbers and underscores (not dashes!) should work fine too.)
91 add_shortcode( 'sitemap', 'pagelist_shortcode' );
92 }
93
94 if ( !function_exists('subpages_shortcode') ) {
95 function subpages_shortcode( $atts ) {
96 global $post;
97 $return = '';
98 extract( shortcode_atts( array(
99 'depth' => '0',
100 //'child_of' => '0',
101 'exclude' => '0',
102 'exclude_tree' => '',
103 'include' => '0',
104 'title_li' => '',
105 'number' => '',
106 'offset' => '',
107 'meta_key' => '',
108 'meta_value' => '',
109 'show_date' => '',
110 'sort_column' => 'menu_order, post_title',
111 'sort_order' => 'ASC',
112 'link_before' => '',
113 'link_after' => '',
114 'class' => ''
115 ), $atts ) );
116
117 $page_list_args = array(
118 'depth' => $depth,
119 'child_of' => $post->ID,
120 'exclude' => pagelist_norm_params($exclude),
121 'exclude_tree' => $exclude_tree,
122 'include' => $include,
123 'title_li' => $title_li,
124 'number' => $number,
125 'offset' => $offset,
126 'meta_key' => $meta_key,
127 'meta_value' => $meta_value,
128 'show_date' => $show_date,
129 'date_format' => get_option('date_format'),
130 'echo' => 0,
131 'authors' => '',
132 'sort_column' => $sort_column,
133 'sort_order' => $sort_order,
134 'link_before' => $link_before,
135 'link_after' => $link_after,
136 'walker' => ''
137 );
138 $list_pages = wp_list_pages( $page_list_args );
139
140 if ($list_pages) {
141 $return = "\n".'<!-- powered by Page-list plugin ver.1.8 (wordpress.org/extend/plugins/page-list/) -->'."\n";
142 $return .= '<ul class="page-list subpages-page-list '.$class.'">'."\n".$list_pages."\n".'</ul>';
143 }else{
144 $return = '';
145 }
146 return $return;
147 }
148 add_shortcode( 'subpages', 'subpages_shortcode' );
149 add_shortcode( 'sub_pages', 'subpages_shortcode' );
150 add_shortcode( 'sub-pages', 'subpages_shortcode' ); // not good (Shortcode names should be all lowercase and use all letters, but numbers and underscores (not dashes!) should work fine too.)
151 add_shortcode( 'children', 'subpages_shortcode' );
152 }
153
154 if ( !function_exists('siblings_shortcode') ) {
155 function siblings_shortcode( $atts ) {
156 global $post;
157 $return = '';
158 extract( shortcode_atts( array(
159 'depth' => '0',
160 //'child_of' => '0',
161 'exclude' => '0',
162 'exclude_tree' => '',
163 'include' => '0',
164 'title_li' => '',
165 'number' => '',
166 'offset' => '',
167 'meta_key' => '',
168 'meta_value' => '',
169 'show_date' => '',
170 'sort_column' => 'menu_order, post_title',
171 'sort_order' => 'ASC',
172 'link_before' => '',
173 'link_after' => '',
174 'class' => ''
175 ), $atts ) );
176
177 if( $exclude == 'current' || $exclude == 'this' ){
178 $exclude = $post->ID;
179 }
180
181 $page_list_args = array(
182 'depth' => $depth,
183 'child_of' => $post->post_parent,
184 'exclude' => pagelist_norm_params($exclude),
185 'exclude_tree' => $exclude_tree,
186 'include' => $include,
187 'title_li' => $title_li,
188 'number' => $number,
189 'offset' => $offset,
190 'meta_key' => $meta_key,
191 'meta_value' => $meta_value,
192 'show_date' => $show_date,
193 'date_format' => get_option('date_format'),
194 'echo' => 0,
195 'authors' => '',
196 'sort_column' => $sort_column,
197 'sort_order' => $sort_order,
198 'link_before' => $link_before,
199 'link_after' => $link_after,
200 'walker' => ''
201 );
202 $list_pages = wp_list_pages( $page_list_args );
203
204 if ($list_pages) {
205 $return = "\n".'<!-- powered by Page-list plugin ver.1.8 (wordpress.org/extend/plugins/page-list/) -->'."\n";
206 $return .= '<ul class="page-list siblings-page-list '.$class.'">'."\n".$list_pages."\n".'</ul>';
207 }else{
208 $return = '';
209 }
210 return $return;
211 }
212 add_shortcode( 'siblings', 'siblings_shortcode' );
213 }
214
215 if ( !function_exists('pagelist_ext_shortcode') ) {
216 function pagelist_ext_shortcode( $atts ) {
217 global $post;
218 $return = '';
219 extract( shortcode_atts( array(
220 'show_image' => 1,
221 'show_title' => 1,
222 'show_content' => 1,
223 'limit_content' => 250,
224 'image_width' => '50',
225 'image_height' => '50',
226 'child_of' => '0',
227 'sort_order' => 'ASC',
228 'sort_column' => 'menu_order, post_title',
229 'hierarchical' => 1,
230 'exclude' => '0',
231 'include' => '0',
232 'meta_key' => '',
233 'meta_value' => '',
234 'authors' => '',
235 'parent' => -1,
236 'exclude_tree' => '',
237 'number' => '',
238 'offset' => 0,
239 'post_type' => 'page',
240 'post_status' => 'publish',
241 'class' => '',
242 'strip_tags' => 1
243 ), $atts ) );
244
245 if( $child_of == '0' ){
246 $child_of = $post->ID;
247 }
248
249 $page_list_ext_args = array(
250 'show_image' => $show_image,
251 'show_title' => $show_title,
252 'show_content' => $show_content,
253 'limit_content' => $limit_content,
254 'image_width' => $image_width,
255 'image_height' => $image_height,
256 'child_of' => pagelist_norm_params($child_of),
257 'sort_order' => $sort_order,
258 'sort_column' => $sort_column,
259 'hierarchical' => $hierarchical,
260 'exclude' => pagelist_norm_params($exclude),
261 'include' => $include,
262 'meta_key' => $meta_key,
263 'meta_value' => $meta_value,
264 'authors' => $authors,
265 'parent' => $parent,
266 'exclude_tree' => $exclude_tree,
267 'number' => $number,
268 'offset' => $offset,
269 'post_type' => $post_type,
270 'post_status' => $post_status,
271 'class' => $class,
272 'strip_tags' => $strip_tags
273 );
274 $list_pages = get_pages( $page_list_ext_args );
275 $list_pages_html = '';
276 foreach($list_pages as $page){
277 $link = get_permalink( $page->ID );
278 $list_pages_html .= '<div class="page-list-ext-item">';
279 if( $show_image == 1 ){
280 if( get_the_post_thumbnail($page->ID) ){
281 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.$page->post_title.'">';
282 $list_pages_html .= get_the_post_thumbnail($page->ID, array($image_width,$image_height));
283 $list_pages_html .= '</a></div> ';
284 }
285 }
286 if( $show_title == 1 ){
287 $list_pages_html .= '<h3 class="page-list-ext-title"><a href="'.$link.'" title="'.$page->post_title.'">'.$page->post_title.'</a></h3>';
288 }
289 if( $show_content == 1 ){
290 //$content = apply_filters('the_content', $page->post_content);
291 //$content = str_replace(']]>', ']]&gt;', $content);
292 $content = page_list_parse_content( $page->post_content, $limit_content, $strip_tags );
293
294 $list_pages_html .= '<div class="page-list-ext-item-content">'.$content.'</div>';
295 }
296
297 $list_pages_html .= '</div>'."\n";
298 }
299 if ($list_pages_html) {
300 $return = "\n".'<!-- powered by Page-list plugin ver.1.8 (wordpress.org/extend/plugins/page-list/) -->'."\n";
301 $return .= '<div class="page-list page-list-ext '.$class.'">'."\n".$list_pages_html."\n".'</div>';
302 }else{
303 $return = '';
304 }
305 return $return;
306 }
307 add_shortcode( 'pagelist_ext', 'pagelist_ext_shortcode' );
308 }
309
310
311 if ( !function_exists('page_list_parse_content') ) {
312 function page_list_parse_content($content, $limit_content = 250, $strip_tags = 1) {
313 $output = '';
314 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
315 $content = explode($matches[0], $content, 2);
316
317 } else {
318 if( $strip_tags ){
319 $content_stripped = strip_tags($content); // ,'<p>'
320 }else{
321 $content_stripped = $content;
322 }
323
324 if( strlen($content_stripped) > $limit_content ){
325 $pos = strpos($content_stripped, ' ', $limit_content);
326 if ($pos !== false) {
327 $first_space_pos = $pos;
328 }else{
329 $first_space_pos = $limit_content;
330 }
331 $content_cut = mb_substr($content_stripped, 0, $first_space_pos,'UTF-8');
332 $content = $content_cut.'...';
333 }else{
334 $content = $content_stripped;
335 }
336 $content = array($content);
337 }
338 $output .= $content[0];
339 $output = force_balance_tags($output);
340 return $output;
341 }
342 }