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

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