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

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