-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget-class.php
106 lines (92 loc) · 4.41 KB
/
widget-class.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
//Custom Page Menus WIDGET
class CustomPagesWidget extends WP_Widget {
/** constructor */
function CustomPagesWidget() {
global $post;
parent::WP_Widget(false, $name = 'Custom Page Menus');
}
/** @see WP_Widget::widget */
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
$sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
$thumb = isset($instance['thumb']) ? $instance['thumb'] : NULL;
$include_IDs = get_post_custom_values('custom-pages');
if (isset($include_IDs[0])){
$include_IDs = $include_IDs[0];
}else{ $include_IDs = 'None'; }
$cpMenu = get_pages( 'sort_column='.$sortby.'&include='.$include_IDs );
if ($cpMenu):
echo $before_widget;
echo $before_title. $title .$after_title;
echo '<ul>';
foreach ($cpMenu as $page)
{
echo '<li class="custom-pages-menu-item">';
if ((isset( $featured_image) && $featured_image) && $thumb){
echo '<a href="';
echo get_permalink($page->ID).'" class="custom-pages-menu-thumb" title="';
echo $page->post_name.'">';
echo get_the_post_thumbnail($page->ID);
echo '</a>';
}
echo '<a href="';
echo get_permalink($page->ID).'" title="';
echo $page->post_name.'">';
if (get_post_custom_values('custom-page-menu-title', $page->ID))
{
$set_title = get_post_custom_values('custom-page-menu-title', $page->ID);
echo '<span>'.$set_title[0].'</span>';
}else{
echo '<span>'.$page->post_title.'</span>';
}
echo '</a>';
echo '</li>';
}
echo '</ul>';
echo $after_widget;
else:
echo '<span style="display: none;">'.count($cpMenu).'</span>';
endif;
}
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['thumb'] = strip_tags($new_instance['thumb']);
if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
$instance['sortby'] = $new_instance['sortby'];
} else {
$instance['sortby'] = 'menu_order';
}
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
if(array_key_exists('title', $instance)){
$title = esc_attr($instance['title']); }else{$title = '';}
if(array_key_exists('sortby', $instance)){
$sortby = $instance['sortby'];
}else{$sortby = '';}
if(array_key_exists('thumb', $instance)){
$thumb = esc_attr($instance['thumb']);
}else{$thumb = 0;}
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
<p><input id="<?php echo $this->get_field_id('thumb'); ?>" name="<?php echo $this->get_field_name('thumb'); ?>" <?php if($thumb){ echo 'checked="checked"'; } ?> type="checkbox" value= "1" ><label for="<?php echo $this->get_field_id('thumb'); ?>"> Include Featured Images</label></p>
<p>
<label for="<?php echo $this->get_field_id('sortby'); ?>"><?php _e( 'Sort by:' ); ?></label>
<select name="<?php echo $this->get_field_name('sortby'); ?>" id="<?php echo $this->get_field_id('sortby'); ?>" class="widefat">
<option value="post_title"<?php selected( $sortby, 'post_title' ); ?>><?php _e('Page Title'); ?></option>
<option value="menu_order"<?php selected( $sortby, 'menu_order' ); ?>><?php _e('Page Order'); ?></option>
<option value="post_date"<?php selected( $sortby, 'post_date' ); ?>><?php _e('Page Date'); ?></option>
<option value="ID"<?php selected( $sortby, 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
</select>
</p>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget("CustomPagesWidget");'));
//custom Pages WIDGET -- END