-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSubPages.php
executable file
·70 lines (57 loc) · 1.61 KB
/
SubPages.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
<?php
/*
Plugin Name: Display Subpages Widget
Description: Show <?php the_subpages() ?>
Author: Lincoln Baxter
Version: 1.1
*/
/*
Simply displays:
<div class="subpages">
<?php the_subpages() ?>
</div>
*/
function widget_subpages_init() {
if ( !function_exists('register_sidebar_widget') )
{
return;
}
function widget_subpages($args)
{
extract($args);
echo $before_widget.'<div class="subpages">';
the_subpages();
echo '</div>'.$after_widget;
}
function widget_subpages_control() {
echo 'There are no settings for this widget.';
}
// This registers our widget so it appears with the other available
// widgets and can be dragged and dropped into any active sidebars.
register_sidebar_widget(array('Sub Page Menu', 'widgets'), 'widget_subpages');
// This registers our optional widget control form. Because of this
// our widget will have a button that reveals a 300x100 pixel form.
register_widget_control(array('Sub Page Menu', 'widgets'), 'widget_subpages_control', 300, 190);
}
function the_subpages()
{
global $post, $wpdb;
if ( is_page() )
{
if ( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type='page' AND post_parent = ".$post->ID) > 0 ){
$subpages = $post->ID;
}
else if ( $post->post_parent != 0 ){
$subpages = $post->post_parent;
}
if ($subpages)
{
echo '<ul>' . "\n";
wp_list_pages('title_li=&child_of='.$subpages);
echo '</ul>' . "\n";
}
}
}
// Run our code later in case this loads prior to any required plugins.
add_action('widgets_init', 'widget_subpages_init');
?>