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

376 lines 12.5 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.0
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.0', '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.0 (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.0 (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.0 (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,
272 'offset' => $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 foreach($list_pages as $page){
285 $link = get_permalink( $page->ID );
286 $list_pages_html .= '<div class="page-list-ext-item">';
287 if( $show_image == 1 ){
288 if (function_exists('get_the_post_thumbnail')) {
289 if( get_the_post_thumbnail($page->ID) ){
290 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.$page->post_title.'">';
291 $list_pages_html .= get_the_post_thumbnail($page->ID, array($image_width,$image_height));
292 $list_pages_html .= '</a></div> ';
293 }
294 }
295 }
296 if( $show_title == 1 ){
297 $list_pages_html .= '<h3 class="page-list-ext-title"><a href="'.$link.'" title="'.$page->post_title.'">'.$page->post_title.'</a></h3>';
298 }
299 if( $show_content == 1 ){
300 //$content = apply_filters('the_content', $page->post_content);
301 //$content = str_replace(']]>', ']]&gt;', $content);
302 $content = page_list_parse_content( $page->post_content, $limit_content, $strip_tags );
303 $list_pages_html .= '<div class="page-list-ext-item-content">'.$content.'</div>';
304 }
305 if( $show_child_count == 1 ){
306 $count_subpages = count(get_pages("child_of=".$page->ID));
307 if( $count_subpages > 0 ){ // hide empty
308 $child_count_pos = strpos($child_count_template, '%child_count%'); // check if we have %child_count% marker in template
309 if($child_count_pos === false) { // %child_count% not found in template
310 $child_count_template_html = $child_count_template.' '.$count_subpages;
311 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
312 } else { // %child_count% found in template
313 $child_count_template_html = str_replace('%child_count%', $count_subpages, $child_count_template);
314 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
315 }
316 }
317 }
318 if( $show_meta_key != '' ){
319 $post_meta = get_post_meta($page->ID, $show_meta_key, true);
320 if( !empty($post_meta) ){ // hide empty
321 $meta_pos = strpos($meta_template, '%meta%'); // check if we have %meta% marker in template
322 if($meta_pos === false) { // %meta% not found in template
323 $meta_template_html = $meta_template.' '.$post_meta;
324 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
325 } else { // %meta% found in template
326 $meta_template_html = str_replace('%meta%', $post_meta, $meta_template);
327 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
328 }
329 }
330 }
331 $list_pages_html .= '</div>'."\n";
332 }
333 if ($list_pages_html) {
334 $return = "\n".'<!-- powered by Page-list plugin ver.2.0 (wordpress.org/extend/plugins/page-list/) -->'."\n";
335 $return .= '<div class="page-list page-list-ext '.$class.'">'."\n".$list_pages_html."\n".'</div>';
336 }else{
337 $return = '';
338 }
339 return $return;
340 }
341 add_shortcode( 'pagelist_ext', 'pagelist_ext_shortcode' );
342 }
343
344
345 if ( !function_exists('page_list_parse_content') ) {
346 function page_list_parse_content($content, $limit_content = 250, $strip_tags = 1) {
347 $output = '';
348 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
349 $content = explode($matches[0], $content, 2);
350
351 } else {
352 if( $strip_tags ){
353 $content_stripped = strip_tags($content); // ,'<p>'
354 }else{
355 $content_stripped = $content;
356 }
357
358 if( strlen($content_stripped) > $limit_content ){
359 $pos = strpos($content_stripped, ' ', $limit_content);
360 if ($pos !== false) {
361 $first_space_pos = $pos;
362 }else{
363 $first_space_pos = $limit_content;
364 }
365 $content_cut = mb_substr($content_stripped, 0, $first_space_pos,'UTF-8');
366 $content = $content_cut.'...';
367 }else{
368 $content = $content_stripped;
369 }
370 $content = array($content);
371 }
372 $output .= $content[0];
373 $output = force_balance_tags($output);
374 return $output;
375 }
376 }