Ad for Tradeomics

WordPress Widget List Sub-Pages

A WordPress widget to list the sub-pages of the current page or the siblings if the current page is a sub-page.

Get the code from http://pastebin.com/2MxHfvx1 and place this code within functions.php which is in your theme folder.

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
/* ----------------------------------
WIDGET: LIST SUB PAGES OR SIBLINGS
IF HAS A PARENT WITH SUB PAGES.
---------------------------------- */

class CAOASubPages extends WP_Widget {
function CAOASubPages() {
$options = array('classname' => 'widget-sub-pages', 'description' => 'Get a list of the sub pages from the current page.');
parent::WP_Widget(false, $name = 'List Sub Pages of Current Page', $options);
}

function widget($args){
global $post;
extract($args);

if($post->post_parent):
$ancestors=get_post_ancestors($post->ID);
$root=count($ancestors)-1;
$postID = $ancestors[$root];
else:
$postID = $post->ID;
endif;

$wlp_args = array(
'child_of' => $postID,
'title_li' => __('
<div class="title">'
.get_the_title($post-&gt;post_parent).'</div>
'
),
'echo' =&gt; 0,
);
$wp_list_pages = wp_list_pages($wlp_args);

if($wp_list_pages):
print $before_widget;
print '
<ul>
<ul>'
;</ul>
</ul>
&nbsp;
<ul>
<ul>print $wp_list_pages;</ul>
</ul>
&nbsp;
<ul>print '</ul>
'
;
print $after_widget;
endif;
}
}

add_action('widgets_init', create_function('', 'return register_widget("CAOASubPages");'));

  • http://hunterscreekfl.com/ Hunterfisher33

    Very nice and good for search right?