| 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_image] shortcodes. |
| 6 |
Version: 1.5 |
| 7 |
Author: webvitaly |
| 8 |
Author Email: webvitaly(at)gmail.com |
| 9 |
Author URI: http://web-profile.com.ua/wordpress/ |
| 10 |
|
| 11 |
Future features: |
| 12 |
- add support exclude="current,5"; |
| 13 |
- exclude_by_alias; |
| 14 |
- exclude_front_page; |
| 15 |
- exclude_post_page; |
| 16 |
*/ |
| 17 |
|
| 18 |
if ( !function_exists('pagelist_shortcode') ) { |
| 19 |
function pagelist_shortcode( $atts ) { |
| 20 |
global $post; |
| 21 |
$return = ''; |
| 22 |
extract( shortcode_atts( array( |
| 23 |
'depth' => '0', |
| 24 |
'child_of' => '0', |
| 25 |
'exclude' => '0', |
| 26 |
'exclude_tree' => '', |
| 27 |
'include' => '0', |
| 28 |
'title_li' => '', |
| 29 |
'number' => '', |
| 30 |
'offset' => '', |
| 31 |
'meta_key' => '', |
| 32 |
'meta_value' => '', |
| 33 |
'show_date' => '', |
| 34 |
'sort_column' => 'menu_order, post_title', |
| 35 |
'sort_order' => 'ASC', |
| 36 |
'link_before' => '', |
| 37 |
'link_after' => '', |
| 38 |
'class' => '' |
| 39 |
), $atts ) ); |
| 40 |
|
| 41 |
if( $child_of == 'current' || $child_of == 'this' ){ |
| 42 |
$child_of = $post->ID; |
| 43 |
} |
| 44 |
if( $child_of == 'parent' ){ |
| 45 |
$child_of = $post->post_parent; |
| 46 |
} |
| 47 |
if( $exclude == 'current' || $exclude == 'this' ){ |
| 48 |
$exclude = $post->ID; |
| 49 |
} |
| 50 |
|
| 51 |
$page_list_args = array( |
| 52 |
'depth' => $depth, |
| 53 |
'child_of' => $child_of, |
| 54 |
'exclude' => $exclude, |
| 55 |
'exclude_tree' => $exclude_tree, |
| 56 |
'include' => $include, |
| 57 |
'title_li' => $title_li, |
| 58 |
'number' => $number, |
| 59 |
'offset' => $offset, |
| 60 |
'meta_key' => $meta_key, |
| 61 |
'meta_value' => $meta_value, |
| 62 |
'show_date' => $show_date, |
| 63 |
'date_format' => get_option('date_format'), |
| 64 |
'echo' => 0, |
| 65 |
'authors' => '', |
| 66 |
'sort_column' => $sort_column, |
| 67 |
'sort_order' => $sort_order, |
| 68 |
'link_before' => $link_before, |
| 69 |
'link_after' => $link_after, |
| 70 |
'walker' => '' |
| 71 |
); |
| 72 |
$list_pages = wp_list_pages( $page_list_args ); |
| 73 |
|
| 74 |
if ($list_pages) { |
| 75 |
$return = "\n".'<!-- powered by Page-list plugin ver.1.5 (wordpress.org/extend/plugins/page-list/) -->'."\n"; |
| 76 |
$return .= '<ul class="page-list '.$class.'">'."\n".$list_pages."\n".'</ul>'; |
| 77 |
}else{ |
| 78 |
$return = ''; |
| 79 |
} |
| 80 |
return $return; |
| 81 |
} |
| 82 |
add_shortcode( 'pagelist', 'pagelist_shortcode' ); |
| 83 |
add_shortcode( 'page_list', 'pagelist_shortcode' ); |
| 84 |
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.) |
| 85 |
add_shortcode( 'sitemap', 'pagelist_shortcode' ); |
| 86 |
} |
| 87 |
|
| 88 |
if ( !function_exists('subpages_shortcode') ) { |
| 89 |
function subpages_shortcode( $atts ) { |
| 90 |
global $post; |
| 91 |
$return = ''; |
| 92 |
extract( shortcode_atts( array( |
| 93 |
'depth' => '0', |
| 94 |
//'child_of' => '0', |
| 95 |
'exclude' => '0', |
| 96 |
'exclude_tree' => '', |
| 97 |
'include' => '0', |
| 98 |
'title_li' => '', |
| 99 |
'number' => '', |
| 100 |
'offset' => '', |
| 101 |
'meta_key' => '', |
| 102 |
'meta_value' => '', |
| 103 |
'show_date' => '', |
| 104 |
'sort_column' => 'menu_order, post_title', |
| 105 |
'sort_order' => 'ASC', |
| 106 |
'link_before' => '', |
| 107 |
'link_after' => '', |
| 108 |
'class' => '' |
| 109 |
), $atts ) ); |
| 110 |
|
| 111 |
$page_list_args = array( |
| 112 |
'depth' => $depth, |
| 113 |
'child_of' => $post->ID, |
| 114 |
'exclude' => $exclude, |
| 115 |
'exclude_tree' => $exclude_tree, |
| 116 |
'include' => $include, |
| 117 |
'title_li' => $title_li, |
| 118 |
'number' => $number, |
| 119 |
'offset' => $offset, |
| 120 |
'meta_key' => $meta_key, |
| 121 |
'meta_value' => $meta_value, |
| 122 |
'show_date' => $show_date, |
| 123 |
'date_format' => get_option('date_format'), |
| 124 |
'echo' => 0, |
| 125 |
'authors' => '', |
| 126 |
'sort_column' => $sort_column, |
| 127 |
'sort_order' => $sort_order, |
| 128 |
'link_before' => $link_before, |
| 129 |
'link_after' => $link_after, |
| 130 |
'walker' => '' |
| 131 |
); |
| 132 |
$list_pages = wp_list_pages( $page_list_args ); |
| 133 |
|
| 134 |
if ($list_pages) { |
| 135 |
$return = "\n".'<!-- powered by Page-list plugin ver.1.5 (wordpress.org/extend/plugins/page-list/) -->'."\n"; |
| 136 |
$return .= '<ul class="page-list subpages-page-list '.$class.'">'."\n".$list_pages."\n".'</ul>'; |
| 137 |
}else{ |
| 138 |
$return = ''; |
| 139 |
} |
| 140 |
return $return; |
| 141 |
} |
| 142 |
add_shortcode( 'subpages', 'subpages_shortcode' ); |
| 143 |
add_shortcode( 'sub_pages', 'subpages_shortcode' ); |
| 144 |
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.) |
| 145 |
add_shortcode( 'children', 'subpages_shortcode' ); |
| 146 |
} |
| 147 |
|
| 148 |
if ( !function_exists('siblings_shortcode') ) { |
| 149 |
function siblings_shortcode( $atts ) { |
| 150 |
global $post; |
| 151 |
$return = ''; |
| 152 |
extract( shortcode_atts( array( |
| 153 |
'depth' => '0', |
| 154 |
//'child_of' => '0', |
| 155 |
'exclude' => '0', |
| 156 |
'exclude_tree' => '', |
| 157 |
'include' => '0', |
| 158 |
'title_li' => '', |
| 159 |
'number' => '', |
| 160 |
'offset' => '', |
| 161 |
'meta_key' => '', |
| 162 |
'meta_value' => '', |
| 163 |
'show_date' => '', |
| 164 |
'sort_column' => 'menu_order, post_title', |
| 165 |
'sort_order' => 'ASC', |
| 166 |
'link_before' => '', |
| 167 |
'link_after' => '', |
| 168 |
'class' => '' |
| 169 |
), $atts ) ); |
| 170 |
|
| 171 |
if( $exclude == 'current' || $exclude == 'this' ){ |
| 172 |
$exclude = $post->ID; |
| 173 |
} |
| 174 |
|
| 175 |
$page_list_args = array( |
| 176 |
'depth' => $depth, |
| 177 |
'child_of' => $post->post_parent, |
| 178 |
'exclude' => $exclude, |
| 179 |
'exclude_tree' => $exclude_tree, |
| 180 |
'include' => $include, |
| 181 |
'title_li' => $title_li, |
| 182 |
'number' => $number, |
| 183 |
'offset' => $offset, |
| 184 |
'meta_key' => $meta_key, |
| 185 |
'meta_value' => $meta_value, |
| 186 |
'show_date' => $show_date, |
| 187 |
'date_format' => get_option('date_format'), |
| 188 |
'echo' => 0, |
| 189 |
'authors' => '', |
| 190 |
'sort_column' => $sort_column, |
| 191 |
'sort_order' => $sort_order, |
| 192 |
'link_before' => $link_before, |
| 193 |
'link_after' => $link_after, |
| 194 |
'walker' => '' |
| 195 |
); |
| 196 |
$list_pages = wp_list_pages( $page_list_args ); |
| 197 |
|
| 198 |
if ($list_pages) { |
| 199 |
$return = "\n".'<!-- powered by Page-list plugin ver.1.5 (wordpress.org/extend/plugins/page-list/) -->'."\n"; |
| 200 |
$return .= '<ul class="page-list siblings-page-list '.$class.'">'."\n".$list_pages."\n".'</ul>'; |
| 201 |
}else{ |
| 202 |
$return = ''; |
| 203 |
} |
| 204 |
return $return; |
| 205 |
} |
| 206 |
add_shortcode( 'siblings', 'siblings_shortcode' ); |
| 207 |
} |
| 208 |
|
| 209 |
if ( !function_exists('page_list_ext_shortcode') ) { |
| 210 |
function page_list_ext_shortcode( $atts ) { |
| 211 |
global $post; |
| 212 |
$return = ''; |
| 213 |
extract( shortcode_atts( array( |
| 214 |
'image_width' => '40', |
| 215 |
'image_height' => '40', |
| 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 |
), $atts ) ); |
| 233 |
|
| 234 |
if( $child_of == 'current' || $child_of == 'this' || $child_of == '0' ){ |
| 235 |
$child_of = $post->ID; |
| 236 |
} |
| 237 |
|
| 238 |
if( $exclude == 'current' || $exclude == 'this' ){ |
| 239 |
$exclude = $post->ID; |
| 240 |
} |
| 241 |
|
| 242 |
$page_list_image_args = array( |
| 243 |
'image_width' => $image_width, |
| 244 |
'image_height' => $image_height, |
| 245 |
'child_of' => $child_of, |
| 246 |
'sort_order' => $sort_order, |
| 247 |
'sort_column' => $sort_column, |
| 248 |
'hierarchical' => $hierarchical, |
| 249 |
'exclude' => $exclude, |
| 250 |
'include' => $include, |
| 251 |
'meta_key' => $meta_key, |
| 252 |
'meta_value' => $meta_value, |
| 253 |
'authors' => $authors, |
| 254 |
'parent' => $parent, |
| 255 |
'exclude_tree' => $exclude_tree, |
| 256 |
'number' => $number, |
| 257 |
'offset' => $offset, |
| 258 |
'post_type' => $post_type, |
| 259 |
'post_status' => $post_status, |
| 260 |
'class' => $class |
| 261 |
); |
| 262 |
$list_pages = get_pages( $page_list_image_args ); |
| 263 |
$list_pages_html = ''; |
| 264 |
foreach($list_pages as $page){ |
| 265 |
$link = get_permalink( $page->ID ); |
| 266 |
$list_pages_html .= '<li>'; |
| 267 |
if( get_the_post_thumbnail($page->ID) ){ |
| 268 |
$list_pages_html .= '<span class="page-list-ext-item"><a href="'.$link.'" title="'.$page->post_title.'">'; |
| 269 |
$list_pages_html .= get_the_post_thumbnail($page->ID, array($image_width,$image_height)); |
| 270 |
$list_pages_html .= '</a></span> '; |
| 271 |
} |
| 272 |
$list_pages_html .= '<span class="page-list-ext-link-item"><a href="'.$link.'" title="'.$page->post_title.'">'.$page->post_title.'</a></span>'; |
| 273 |
$list_pages_html .= '</li>'."\n"; |
| 274 |
} |
| 275 |
if ($list_pages_html) { |
| 276 |
$return = "\n".'<!-- powered by Page-list plugin ver.1.5 (wordpress.org/extend/plugins/page-list/) -->'."\n"; |
| 277 |
$return .= '<ul class="page-list page-list-ext '.$class.'">'."\n".$list_pages_html."\n".'</ul>'; |
| 278 |
}else{ |
| 279 |
$return = ''; |
| 280 |
} |
| 281 |
return $return; |
| 282 |
} |
| 283 |
add_shortcode( 'pagelist_ext', 'page_list_ext_shortcode' ); |
| 284 |
} |