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

412 lines 13.8 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.9
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', 'pagelist_add_stylesheet');
18 function pagelist_add_stylesheet() {
19 wp_enqueue_style( 'page-list-style', plugins_url( '/css/page-list.css', __FILE__ ), false, '2.9', 'all' );
20 }
21
22 $pagelist_powered_line = "\n".'<!-- Page-list plugin v.2.9 (wordpress.org/extend/plugins/page-list/) -->'."\n";
23
24 if ( !function_exists('pagelist_shortcode') ) {
25 function pagelist_shortcode( $atts ) {
26 global $post, $pagelist_powered_line;
27 $return = '';
28 extract( shortcode_atts( array(
29 'depth' => '0',
30 'child_of' => '0',
31 'exclude' => '0',
32 'exclude_tree' => '',
33 'include' => '0',
34 'title_li' => '',
35 'number' => '',
36 'offset' => '',
37 'meta_key' => '',
38 'meta_value' => '',
39 'show_date' => '',
40 'sort_column' => 'menu_order, post_title',
41 'sort_order' => 'ASC',
42 'link_before' => '',
43 'link_after' => '',
44 'class' => ''
45 ), $atts ) );
46
47 $page_list_args = array(
48 'depth' => $depth,
49 'child_of' => pagelist_norm_params($child_of),
50 'exclude' => pagelist_norm_params($exclude),
51 'exclude_tree' => $exclude_tree,
52 'include' => $include,
53 'title_li' => $title_li,
54 'number' => $number,
55 'offset' => $offset,
56 'meta_key' => $meta_key,
57 'meta_value' => $meta_value,
58 'show_date' => $show_date,
59 'date_format' => get_option('date_format'),
60 'echo' => 0,
61 'authors' => '',
62 'sort_column' => $sort_column,
63 'sort_order' => $sort_order,
64 'link_before' => $link_before,
65 'link_after' => $link_after,
66 'walker' => ''
67 );
68 $list_pages = wp_list_pages( $page_list_args );
69
70 if ($list_pages) {
71 $return = $pagelist_powered_line;
72 $return .= '<ul class="page-list '.$class.'">'."\n".$list_pages."\n".'</ul>';
73 }else{
74 $return = '';
75 }
76 return $return;
77 }
78 add_shortcode( 'pagelist', 'pagelist_shortcode' );
79 add_shortcode( 'page_list', 'pagelist_shortcode' );
80 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.)
81 add_shortcode( 'sitemap', 'pagelist_shortcode' );
82 }
83
84 if ( !function_exists('subpages_shortcode') ) {
85 function subpages_shortcode( $atts ) {
86 global $post, $pagelist_powered_line;
87 $return = '';
88 extract( shortcode_atts( array(
89 'depth' => '0',
90 //'child_of' => '0',
91 'exclude' => '0',
92 'exclude_tree' => '',
93 'include' => '0',
94 'title_li' => '',
95 'number' => '',
96 'offset' => '',
97 'meta_key' => '',
98 'meta_value' => '',
99 'show_date' => '',
100 'sort_column' => 'menu_order, post_title',
101 'sort_order' => 'ASC',
102 'link_before' => '',
103 'link_after' => '',
104 'class' => ''
105 ), $atts ) );
106
107 $page_list_args = array(
108 'depth' => $depth,
109 'child_of' => $post->ID,
110 'exclude' => pagelist_norm_params($exclude),
111 'exclude_tree' => $exclude_tree,
112 'include' => $include,
113 'title_li' => $title_li,
114 'number' => $number,
115 'offset' => $offset,
116 'meta_key' => $meta_key,
117 'meta_value' => $meta_value,
118 'show_date' => $show_date,
119 'date_format' => get_option('date_format'),
120 'echo' => 0,
121 'authors' => '',
122 'sort_column' => $sort_column,
123 'sort_order' => $sort_order,
124 'link_before' => $link_before,
125 'link_after' => $link_after,
126 'walker' => ''
127 );
128 $list_pages = wp_list_pages( $page_list_args );
129
130 if ($list_pages) {
131 $return = $pagelist_powered_line;
132 $return .= '<ul class="page-list subpages-page-list '.$class.'">'."\n".$list_pages."\n".'</ul>';
133 }else{
134 $return = '';
135 }
136 return $return;
137 }
138 add_shortcode( 'subpages', 'subpages_shortcode' );
139 add_shortcode( 'sub_pages', 'subpages_shortcode' );
140 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.)
141 add_shortcode( 'children', 'subpages_shortcode' );
142 }
143
144 if ( !function_exists('siblings_shortcode') ) {
145 function siblings_shortcode( $atts ) {
146 global $post, $pagelist_powered_line;
147 $return = '';
148 extract( shortcode_atts( array(
149 'depth' => '0',
150 //'child_of' => '0',
151 'exclude' => '0',
152 'exclude_tree' => '',
153 'include' => '0',
154 'title_li' => '',
155 'number' => '',
156 'offset' => '',
157 'meta_key' => '',
158 'meta_value' => '',
159 'show_date' => '',
160 'sort_column' => 'menu_order, post_title',
161 'sort_order' => 'ASC',
162 'link_before' => '',
163 'link_after' => '',
164 'class' => ''
165 ), $atts ) );
166
167 if( $exclude == 'current' || $exclude == 'this' ){
168 $exclude = $post->ID;
169 }
170
171 $page_list_args = array(
172 'depth' => $depth,
173 'child_of' => $post->post_parent,
174 'exclude' => pagelist_norm_params($exclude),
175 'exclude_tree' => $exclude_tree,
176 'include' => $include,
177 'title_li' => $title_li,
178 'number' => $number,
179 'offset' => $offset,
180 'meta_key' => $meta_key,
181 'meta_value' => $meta_value,
182 'show_date' => $show_date,
183 'date_format' => get_option('date_format'),
184 'echo' => 0,
185 'authors' => '',
186 'sort_column' => $sort_column,
187 'sort_order' => $sort_order,
188 'link_before' => $link_before,
189 'link_after' => $link_after,
190 'walker' => ''
191 );
192 $list_pages = wp_list_pages( $page_list_args );
193
194 if ($list_pages) {
195 $return = $pagelist_powered_line;
196 $return .= '<ul class="page-list siblings-page-list '.$class.'">'."\n".$list_pages."\n".'</ul>';
197 }else{
198 $return = '';
199 }
200 return $return;
201 }
202 add_shortcode( 'siblings', 'siblings_shortcode' );
203 }
204
205 if ( !function_exists('pagelist_ext_shortcode') ) {
206 function pagelist_ext_shortcode( $atts ) {
207 global $post, $pagelist_powered_line;
208 $return = '';
209 extract( shortcode_atts( array(
210 'show_image' => 1,
211 'show_title' => 1,
212 'show_content' => 1,
213 'limit_content' => 250,
214 'image_width' => '50',
215 'image_height' => '50',
216 'child_of' => '0',
217 'sort_order' => 'ASC',
218 'sort_column' => 'menu_order, post_title',
219 'hierarchical' => 1,
220 'exclude' => '0',
221 'include' => '0',
222 'meta_key' => '',
223 'meta_value' => '',
224 'authors' => '',
225 'parent' => -1,
226 'exclude_tree' => '',
227 'number' => '',
228 'offset' => 0,
229 'post_type' => 'page',
230 'post_status' => 'publish',
231 'class' => '',
232 'strip_tags' => 1,
233 'strip_shortcodes' => 1,
234 'more_tag' => 1,
235 'show_child_count' => 0,
236 'child_count_template' => 'Subpages: %child_count%',
237 'show_meta_key' => '',
238 'meta_template' => '%meta%'
239 ), $atts ) );
240
241 if( $child_of == '0' ){
242 $child_of = $post->ID;
243 }
244
245 $page_list_ext_args = array(
246 'show_image' => $show_image,
247 'show_title' => $show_title,
248 'show_content' => $show_content,
249 'limit_content' => $limit_content,
250 'image_width' => $image_width,
251 'image_height' => $image_height,
252 'child_of' => pagelist_norm_params($child_of),
253 'sort_order' => $sort_order,
254 'sort_column' => $sort_column,
255 'hierarchical' => $hierarchical,
256 'exclude' => pagelist_norm_params($exclude),
257 'include' => $include,
258 'meta_key' => $meta_key,
259 'meta_value' => $meta_value,
260 'authors' => $authors,
261 'parent' => pagelist_norm_params($parent),
262 'exclude_tree' => $exclude_tree,
263 'number' => '', // $number - own counter
264 'offset' => 0, // $offset - own offset
265 'post_type' => $post_type,
266 'post_status' => $post_status,
267 'class' => $class,
268 'strip_tags' => $strip_tags,
269 'strip_shortcodes' => $strip_shortcodes,
270 'more_tag' => $more_tag,
271 'show_child_count' => $show_child_count,
272 'child_count_template' => $child_count_template,
273 'show_meta_key' => $show_meta_key,
274 'meta_template' => $meta_template
275 );
276 $list_pages = get_pages( $page_list_ext_args );
277 $list_pages_html = '';
278 $count = 0;
279 $offset_count = 0;
280 foreach($list_pages as $page){
281 $count++;
282 $offset_count++;
283 if ( !empty( $offset ) && is_numeric( $offset ) && $offset_count <= $offset ) {
284 $count = 0; // number counter to zero if offset is not finished
285 }
286 if ( ( !empty( $offset ) && is_numeric( $offset ) && $offset_count > $offset ) || ( empty( $offset ) ) || ( !empty( $offset ) && !is_numeric( $offset ) ) ) {
287 if ( ( !empty( $number ) && is_numeric( $number ) && $count <= $number ) || ( empty( $number ) ) || ( !empty( $number ) && !is_numeric( $number ) ) ) {
288 $link = get_permalink( $page->ID );
289 $list_pages_html .= '<div class="page-list-ext-item">';
290 if( $show_image == 1 ){
291 if (function_exists('get_the_post_thumbnail')) {
292 if( get_the_post_thumbnail($page->ID) ){
293 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
294 $list_pages_html .= get_the_post_thumbnail($page->ID, array($image_width,$image_height));
295 $list_pages_html .= '</a></div> ';
296 }
297 }
298 }
299 if( $show_title == 1 ){
300 $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>';
301 }
302 if( $show_content == 1 ){
303 //$content = apply_filters('the_content', $page->post_content);
304 //$content = str_replace(']]>', ']]&gt;', $content); // both used in default the_content() function
305
306 if( !empty( $page->post_excerpt ) ){
307 $text_content = $page->post_excerpt;
308 }else{
309 $text_content = $page->post_content;
310 }
311
312 if ( post_password_required($page) ) {
313 $content = '<!-- password protected -->';
314 }else{
315 $content = page_list_parse_content( $text_content, $limit_content, $strip_tags, $strip_shortcodes, $more_tag );
316
317 if( $show_title == 0 ){ // make content as a link if there is no title
318 $content = '<a href="'.$link.'">'.$content.'</a>';
319 }
320 }
321
322 $list_pages_html .= '<div class="page-list-ext-item-content">'.$content.'</div>';
323
324 }
325 if( $show_child_count == 1 ){
326 $count_subpages = count(get_pages("child_of=".$page->ID));
327 if( $count_subpages > 0 ){ // hide empty
328 $child_count_pos = strpos($child_count_template, '%child_count%'); // check if we have %child_count% marker in template
329 if($child_count_pos === false) { // %child_count% not found in template
330 $child_count_template_html = $child_count_template.' '.$count_subpages;
331 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
332 } else { // %child_count% found in template
333 $child_count_template_html = str_replace('%child_count%', $count_subpages, $child_count_template);
334 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
335 }
336 }
337 }
338 if( $show_meta_key != '' ){
339 $post_meta = get_post_meta($page->ID, $show_meta_key, true);
340 if( !empty($post_meta) ){ // hide empty
341 $meta_pos = strpos($meta_template, '%meta%'); // check if we have %meta% marker in template
342 if($meta_pos === false) { // %meta% not found in template
343 $meta_template_html = $meta_template.' '.$post_meta;
344 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
345 } else { // %meta% found in template
346 $meta_template_html = str_replace('%meta%', $post_meta, $meta_template);
347 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
348 }
349 }
350 }
351 $list_pages_html .= '</div>'."\n";
352 }
353 }
354 }
355 if ($list_pages_html) {
356 $return = $pagelist_powered_line;
357 $return .= '<div class="page-list page-list-ext '.$class.'">'."\n".$list_pages_html."\n".'</div>';
358 }else{
359 $return = '';
360 }
361 return $return;
362 }
363 add_shortcode( 'pagelist_ext', 'pagelist_ext_shortcode' );
364 }
365
366 if ( !function_exists('pagelist_norm_params') ) {
367 function pagelist_norm_params( $str ) {
368 global $post;
369 $new_str = $str;
370 $new_str = str_replace('this', $post->ID, $new_str); // exclude this page
371 $new_str = str_replace('current', $post->ID, $new_str); // exclude current page
372 $new_str = str_replace('curent', $post->ID, $new_str); // exclude curent page with mistake
373 $new_str = str_replace('parent', $post->post_parent, $new_str); // exclude parent page
374 return $new_str;
375 }
376 }
377
378 if ( !function_exists('page_list_parse_content') ) {
379 function page_list_parse_content($content, $limit_content = 250, $strip_tags = 1, $strip_shortcodes = 1, $more_tag = 1) {
380
381 if( $more_tag ){
382 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
383 $more_tag = $matches[0];
384 $content = explode($matches[0], $content);
385 $content = $content[0];
386 }
387 }
388
389 if( $strip_shortcodes ){
390 $content = strip_shortcodes( $content );
391 }
392
393 if( $strip_tags ){
394 $content = str_replace('</', ' </', $content); // <p>line1</p><p>line2</p> - adding space between lines
395 $content = strip_tags($content); // ,'<p>'
396 }
397
398 if( strlen($content) > $limit_content ){
399 $pos = strpos($content, ' ', $limit_content); // find first space position
400 if ($pos !== false) {
401 $first_space_pos = $pos;
402 }else{
403 $first_space_pos = $limit_content;
404 }
405 $content = mb_substr($content, 0, $first_space_pos, 'UTF-8') . '...';
406 }
407
408 $output = force_balance_tags($content);
409 return $output;
410 }
411 }
412