PluginProbe
Page-list / 2.4
Page-list v2.4
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 2.4, at page-list.php

393 lines 13.3 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: 2.4
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, '2.4', '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.2.4 (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.2.4 (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.2.4 (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 'show_child_count' => 0,
244 'child_count_template' => 'Subpages: %child_count%',
245 'show_meta_key' => '',
246 'meta_template' => '%meta%'
247 ), $atts ) );
248
249 if( $child_of == '0' ){
250 $child_of = $post->ID;
251 }
252
253 $page_list_ext_args = array(
254 'show_image' => $show_image,
255 'show_title' => $show_title,
256 'show_content' => $show_content,
257 'limit_content' => $limit_content,
258 'image_width' => $image_width,
259 'image_height' => $image_height,
260 'child_of' => pagelist_norm_params($child_of),
261 'sort_order' => $sort_order,
262 'sort_column' => $sort_column,
263 'hierarchical' => $hierarchical,
264 'exclude' => pagelist_norm_params($exclude),
265 'include' => $include,
266 'meta_key' => $meta_key,
267 'meta_value' => $meta_value,
268 'authors' => $authors,
269 'parent' => $parent,
270 'exclude_tree' => $exclude_tree,
271 'number' => '', // $number - own counter
272 'offset' => 0, // $offset - own offset
273 'post_type' => $post_type,
274 'post_status' => $post_status,
275 'class' => $class,
276 'strip_tags' => $strip_tags,
277 'show_child_count' => $show_child_count,
278 'child_count_template' => $child_count_template,
279 'show_meta_key' => $show_meta_key,
280 'meta_template' => $meta_template
281 );
282 $list_pages = get_pages( $page_list_ext_args );
283 $list_pages_html = '';
284 $count = 0;
285 $offset_count = 0;
286 foreach($list_pages as $page){
287 $count++;
288 $offset_count++;
289 if ( !empty( $offset ) && is_numeric( $offset ) && $offset_count <= $offset ) {
290 $count = 0; // number counter to zero if offset is not finished
291 }
292 if ( ( !empty( $offset ) && is_numeric( $offset ) && $offset_count > $offset ) || ( empty( $offset ) ) || ( !empty( $offset ) && !is_numeric( $offset ) ) ) {
293 if ( ( !empty( $number ) && is_numeric( $number ) && $count <= $number ) || ( empty( $number ) ) || ( !empty( $number ) && !is_numeric( $number ) ) ) {
294 $link = get_permalink( $page->ID );
295 $list_pages_html .= '<div class="page-list-ext-item">';
296 if( $show_image == 1 ){
297 if (function_exists('get_the_post_thumbnail')) {
298 if( get_the_post_thumbnail($page->ID) ){
299 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
300 $list_pages_html .= get_the_post_thumbnail($page->ID, array($image_width,$image_height));
301 $list_pages_html .= '</a></div> ';
302 }
303 }
304 }
305 if( $show_title == 1 ){
306 $list_pages_html .= '<h3 class="page-list-ext-title"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">'.esc_attr($page->post_title).'</a></h3>';
307 }
308 if( $show_content == 1 ){
309 //$content = apply_filters('the_content', $page->post_content);
310 //$content = str_replace(']]>', ']]&gt;', $content);
311 if( !empty( $page->post_excerpt ) ){
312 $text_content = $page->post_excerpt;
313 }else{
314 $text_content = $page->post_content;
315 }
316 $content = page_list_parse_content( $text_content, $limit_content, $strip_tags );
317 $list_pages_html .= '<div class="page-list-ext-item-content">'.$content.'</div>';
318 }
319 if( $show_child_count == 1 ){
320 $count_subpages = count(get_pages("child_of=".$page->ID));
321 if( $count_subpages > 0 ){ // hide empty
322 $child_count_pos = strpos($child_count_template, '%child_count%'); // check if we have %child_count% marker in template
323 if($child_count_pos === false) { // %child_count% not found in template
324 $child_count_template_html = $child_count_template.' '.$count_subpages;
325 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
326 } else { // %child_count% found in template
327 $child_count_template_html = str_replace('%child_count%', $count_subpages, $child_count_template);
328 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
329 }
330 }
331 }
332 if( $show_meta_key != '' ){
333 $post_meta = get_post_meta($page->ID, $show_meta_key, true);
334 if( !empty($post_meta) ){ // hide empty
335 $meta_pos = strpos($meta_template, '%meta%'); // check if we have %meta% marker in template
336 if($meta_pos === false) { // %meta% not found in template
337 $meta_template_html = $meta_template.' '.$post_meta;
338 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
339 } else { // %meta% found in template
340 $meta_template_html = str_replace('%meta%', $post_meta, $meta_template);
341 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
342 }
343 }
344 }
345 $list_pages_html .= '</div>'."\n";
346 }
347 }
348 }
349 if ($list_pages_html) {
350 $return = "\n".'<!-- powered by Page-list plugin ver.2.4 (wordpress.org/extend/plugins/page-list/) -->'."\n";
351 $return .= '<div class="page-list page-list-ext '.$class.'">'."\n".$list_pages_html."\n".'</div>';
352 }else{
353 $return = '';
354 }
355 return $return;
356 }
357 add_shortcode( 'pagelist_ext', 'pagelist_ext_shortcode' );
358 }
359
360
361 if ( !function_exists('page_list_parse_content') ) {
362 function page_list_parse_content($content, $limit_content = 250, $strip_tags = 1) {
363 $output = '';
364 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
365 $content = explode($matches[0], $content, 2);
366
367 } else {
368 if( $strip_tags ){
369 $content_stripped = strip_tags($content); // ,'<p>'
370 }else{
371 $content_stripped = $content;
372 }
373
374 if( strlen($content_stripped) > $limit_content ){
375 $pos = strpos($content_stripped, ' ', $limit_content);
376 if ($pos !== false) {
377 $first_space_pos = $pos;
378 }else{
379 $first_space_pos = $limit_content;
380 }
381 $content_cut = mb_substr($content_stripped, 0, $first_space_pos,'UTF-8');
382 $content = $content_cut.'...';
383 }else{
384 $content = $content_stripped;
385 }
386 $content = array($content);
387 }
388 $output .= $content[0];
389 $output = force_balance_tags($output);
390 return $output;
391 }
392 }
393