-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsubpages-extended-shortcode.php
77 lines (64 loc) · 1.96 KB
/
subpages-extended-shortcode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( 'Invalid request.' );
}
function shailan_subpages_shortcode($atts) {
global $post, $subpages_indexes;
extract(shortcode_atts(array(
'depth' => 3,
'show_date' => false,
'date_format' => get_option('date_format'),
'child_of' => -1,
'exclude' => '',
'include' => '',
'title_li' => '',
'echo' => 1,
'authors' => '',
'sort_column' => 'menu_order, post_title',
'sort_order' => 'ASC',
'link_before' => '',
'link_after' => '',
'exceptme' => false,
'childof' => '',
'title' => '',
'rel' => ''
), $atts));
$walker = new Shailan_Walker_Page;
$walker->set_rel( $rel );
if('parent' == $childof || 'parent' == $child_of) {
$parent = $post->post_parent;
} else {
$parent = $childof;
if(-1 != $child_of) { $parent = $child_of; }
if($parent==''){ $parent = $post->ID; }
}
if($exceptme) { $exclude .= ','.$post->ID; }
if($title == '*current*'){ $title = '<h3>' . get_the_title($parent) . '</h3>'; }
$subpages_indexes += 1;
$shortcode_id = $subpages_indexes;
$children = wp_list_pages( 'echo=0&child_of=' . $parent . '&title_li=' );
$subpage_args = array(
'depth' => $depth,
'show_date' => $show_date,
'date_format' => $date_format,
'child_of' => $parent,
'exclude' => $exclude,
'include' => $include,
'title_li' => '',
'echo' => false,
'authors' => $authors,
'sort_column' => $sort_column,
'sort_order' => $sort_order,
'link_before' => $link_before,
'link_after' => $link_after,
'walker' => $walker );
if ($children) {
$subpages = '<div id="shailan-subpages-' . $post->ID . '-' .$shortcode_id.'">'.$title.'<ul class="subpages">';
$subpages .= wp_list_pages( $subpage_args );
$subpages .= '</ul></div>';
} else {
$subpages = '"' . get_the_title($parent) . '" doesn\'t have any sub pages.';
}
return $subpages;
}
add_shortcode('subpages', 'shailan_subpages_shortcode');