Advanced Sidebar Menu - Version 2.0.1

Version Description

Download this release

Release Info

Developer Mat Lipe
Plugin Icon 128x128 Advanced Sidebar Menu
Version 2.0.1
Comparing to
See all releases

Code changes from version 2.0.0 to 2.0.1

Files changed (3) hide show
  1. advanced-sidebar-menu.php +50 -50
  2. readme.txt +2 -2
  3. screenshot-1.PNG +0 -0
advanced-sidebar-menu.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Advanced Sidebar Menu
4
  Plugin URI: http://lipeimagination.info
5
  Description: Creates dynamic menu based on child/parent relationship.
6
  Author: Mat Lipe
7
- Version: 2.0
8
  Author URI: http://lipeimagination.info
9
  Since: 1/24/12
10
  Email: mat@lipeimagination.info
@@ -21,42 +21,42 @@ class advanced_sidebar_menu extends WP_Widget {
21
  function form( $instance ) {
22
  require( 'advanced-sidebar-menu.js' );
23
  ?>
24
-
25
-
26
-
27
- <p> Include Parent Page <input id="<?php echo $this->get_field_name('include_parent'); ?>"
28
- name="<?php echo $this->get_field_name('include_parent'); ?>" type="checkbox" value="checked"
29
  <?php echo $instance['include_parent']; ?>/></p>
30
-
31
-
32
  <p> Include Parent Even With No Children<input id="<?php echo $this->get_field_name('include_childless_parent'); ?>"
33
- name="<?php echo $this->get_field_name('include_childless_parent'); ?>" type="checkbox" value="checked"
34
  <?php echo $instance['include_childless_parent']; ?>/></p>
35
-
36
- <p> Pages to Exclude, Comma Separated:<input id="<?php echo $this->get_field_name('exclude'); ?>"
37
  name="<?php echo $this->get_field_name('exclude'); ?>" type="text" value="<?php echo $instance['exclude']; ?>"/></p>
38
-
39
- <p> Always Display Child Pages <input id="<?php echo $this->get_field_name('display_all'); ?>"
40
- name="<?php echo $this->get_field_name('display_all'); ?>" type="checkbox" value="checked"
41
  onclick="javascript:reveal_element( 'levels-<?php echo $this->get_field_name('levels'); ?>' )"
42
  <?php echo $instance['display_all']; ?>/></p>
43
-
44
- <span id="levels-<?php echo $this->get_field_name('levels'); ?>" style="<?php
45
  if( $instance['display_all'] == checked ){
46
  echo 'display:block';
47
  } else {
48
  echo 'display:none';
49
- } ?>">
50
- <p> Levels to Display <select id="<?php echo $this->get_field_name('levels'); ?>"
51
  name="<?php echo $this->get_field_name('levels'); ?>">
52
- <?php
53
  for( $i= 1; $i<6; $i++ ){
54
  if( $i == $instance['levels'] ){
55
  echo '<option value="'.$i.'" selected>'.$i.'</option>';
56
  } else {
57
  echo '<option value="'.$i.'">'.$i.'</option>';
58
  }
59
- }
60
  echo '</select></p></span>';
61
  }
62
 
@@ -93,101 +93,101 @@ class advanced_sidebar_menu extends WP_Widget {
93
  global $wpdb;
94
  global $p;
95
  global $post;
96
-
97
  #-- Create a usable array of the excluded pages
98
  $exclude = explode(',', $instance['exclude']);
99
-
100
-
101
  #-- if the post has parrents
102
  if($post->ancestors){
103
-
104
  $parent = $wpdb->get_var( "SELECT post_parent from wp_posts WHERE ID=".$post->ID );
105
-
106
  //--- If there is a parent of the post set $p to it and check if there is a parent as well
107
  while($parent != FALSE){
108
  $p = $parent;
109
  $parent = $wpdb->get_var( "SELECT post_parent from wp_posts WHERE ID=".$parent);
110
  }
111
-
112
  } else {
113
  #--------- If this is the parent ------------------------------------------------
114
  $p = $post->ID;
115
  }
116
-
117
  #-- Makes this work with all table prefixes
118
  #-- Added 1/22/12
119
  global $table_prefix;
120
-
121
 
122
  $result = $wpdb->get_results( "SELECT ID FROM ".$table_prefix."posts WHERE post_parent = $p AND post_type='page' Order by menu_order" );
123
-
124
  #---- if there are no children do not display the parent unless it is check to do so
125
  if($result != false || $instance['include_childless_parent'] == 'checked' ){
126
-
127
- //Start the menu
128
  echo '<div id="'.$args['widget_id'].'" class="advanced-sidebar-menu widget">';
129
-
130
- echo '<ul class="parent-sidebar-menu" >';
131
  #-- if the checkbox to include parent is checked
132
  if( $instance['include_parent'] == 'checked' ){
133
  $parent_toggle = TRUE;
134
-
135
- #-- If the page is not excluded from the menu
136
- if( !in_array($p, $exclude) ){
137
  #-- list the parent page
138
  wp_list_pages("sort_column=menu_order&title_li=&echo=1&depth=1&include=".$p);
139
  }
140
-
141
  }
142
  }
143
 
144
  //=----------------------------------- makes the Child Pages list -----------------------------------------
145
-
146
  //If there are children start the Child Sidebar Menu
147
  if( $result != FALSE ){
148
  echo '<ul class="child-sidebar-menu">';
149
-
150
  #-- If they want all the pages displayed always
151
  if( $instance['display_all'] == 'checked' ){
152
  wp_list_pages("sort_column=menu_order&title_li=&echo=1&child_of=".$p."&depth=".$instance['levels']."&exclude=".$instance['exclude']);
153
  } else {
154
-
155
  #-- Display children of current page's parent only
156
  foreach($result as $pID){
157
-
158
  #-- If the page is not in the excluded ones
159
  if( !in_array($pID->ID, $exclude) ){
160
  #--echo the current page from the $result
161
  wp_list_pages("sort_column=menu_order&title_li=&echo=1&depth=1&include=".$pID->ID);
162
  }
163
-
164
  #-- if the link that was just listed is the current page we are on
165
  if($pID->ID == $post->ID or $pID->ID == $post->post_parent or @in_array($pID->ID, $post->ancestors) ){
166
-
167
  $kids = $wpdb->get_results( "SELECT ID FROM ".$table_prefix."posts WHERE post_parent = ".$pID->ID." AND post_type='page' " );
168
  if( $kids != FALSE ){
169
-
170
  #-- Create a new menu with all the children under it
171
  echo '<ul class="grandchild-sidebar-menu">';
172
 
173
  wp_list_pages("sort_column=menu_order&title_li=&echo=1&exclude=".$instance['exclude']."&depth=3&child_of=".$pID->ID);
174
-
175
  echo '</ul>';
176
  }
177
  }
178
  }
179
  }
180
-
181
  #-- Close the First Level menu
182
  echo '</ul><!-- End child-sidebar-menu -->';
183
-
184
  }
185
  #-- If there was a menu close it off
186
  if($result != false || $instance['include_childless_parent'] == 'checked' ){
187
-
188
  echo '</ul></div><!-- end of very-custom-menu -->';
189
  }
190
-
191
  } #== /widget()
192
-
193
  } #== /Class
4
  Plugin URI: http://lipeimagination.info
5
  Description: Creates dynamic menu based on child/parent relationship.
6
  Author: Mat Lipe
7
+ Version: 2.0.1
8
  Author URI: http://lipeimagination.info
9
  Since: 1/24/12
10
  Email: mat@lipeimagination.info
21
  function form( $instance ) {
22
  require( 'advanced-sidebar-menu.js' );
23
  ?>
24
+
25
+
26
+
27
+ <p> Include Parent Page <input id="<?php echo $this->get_field_name('include_parent'); ?>"
28
+ name="<?php echo $this->get_field_name('include_parent'); ?>" type="checkbox" value="checked"
29
  <?php echo $instance['include_parent']; ?>/></p>
30
+
31
+
32
  <p> Include Parent Even With No Children<input id="<?php echo $this->get_field_name('include_childless_parent'); ?>"
33
+ name="<?php echo $this->get_field_name('include_childless_parent'); ?>" type="checkbox" value="checked"
34
  <?php echo $instance['include_childless_parent']; ?>/></p>
35
+
36
+ <p> Pages to Exclude, Comma Separated:<input id="<?php echo $this->get_field_name('exclude'); ?>"
37
  name="<?php echo $this->get_field_name('exclude'); ?>" type="text" value="<?php echo $instance['exclude']; ?>"/></p>
38
+
39
+ <p> Always Display Child Pages <input id="<?php echo $this->get_field_name('display_all'); ?>"
40
+ name="<?php echo $this->get_field_name('display_all'); ?>" type="checkbox" value="checked"
41
  onclick="javascript:reveal_element( 'levels-<?php echo $this->get_field_name('levels'); ?>' )"
42
  <?php echo $instance['display_all']; ?>/></p>
43
+
44
+ <span id="levels-<?php echo $this->get_field_name('levels'); ?>" style="<?php
45
  if( $instance['display_all'] == checked ){
46
  echo 'display:block';
47
  } else {
48
  echo 'display:none';
49
+ } ?>">
50
+ <p> Levels to Display <select id="<?php echo $this->get_field_name('levels'); ?>"
51
  name="<?php echo $this->get_field_name('levels'); ?>">
52
+ <?php
53
  for( $i= 1; $i<6; $i++ ){
54
  if( $i == $instance['levels'] ){
55
  echo '<option value="'.$i.'" selected>'.$i.'</option>';
56
  } else {
57
  echo '<option value="'.$i.'">'.$i.'</option>';
58
  }
59
+ }
60
  echo '</select></p></span>';
61
  }
62
 
93
  global $wpdb;
94
  global $p;
95
  global $post;
96
+
97
  #-- Create a usable array of the excluded pages
98
  $exclude = explode(',', $instance['exclude']);
99
+
100
+
101
  #-- if the post has parrents
102
  if($post->ancestors){
103
+
104
  $parent = $wpdb->get_var( "SELECT post_parent from wp_posts WHERE ID=".$post->ID );
105
+
106
  //--- If there is a parent of the post set $p to it and check if there is a parent as well
107
  while($parent != FALSE){
108
  $p = $parent;
109
  $parent = $wpdb->get_var( "SELECT post_parent from wp_posts WHERE ID=".$parent);
110
  }
111
+
112
  } else {
113
  #--------- If this is the parent ------------------------------------------------
114
  $p = $post->ID;
115
  }
116
+
117
  #-- Makes this work with all table prefixes
118
  #-- Added 1/22/12
119
  global $table_prefix;
120
+
121
 
122
  $result = $wpdb->get_results( "SELECT ID FROM ".$table_prefix."posts WHERE post_parent = $p AND post_type='page' Order by menu_order" );
123
+
124
  #---- if there are no children do not display the parent unless it is check to do so
125
  if($result != false || $instance['include_childless_parent'] == 'checked' ){
126
+
127
+ //Start the menu
128
  echo '<div id="'.$args['widget_id'].'" class="advanced-sidebar-menu widget">';
129
+
130
+ echo '<ul class="parent-sidebar-menu" >';
131
  #-- if the checkbox to include parent is checked
132
  if( $instance['include_parent'] == 'checked' ){
133
  $parent_toggle = TRUE;
134
+
135
+ #-- If the page is not excluded from the menu
136
+ if( !in_array($p, $exclude) ){
137
  #-- list the parent page
138
  wp_list_pages("sort_column=menu_order&title_li=&echo=1&depth=1&include=".$p);
139
  }
140
+
141
  }
142
  }
143
 
144
  //=----------------------------------- makes the Child Pages list -----------------------------------------
145
+
146
  //If there are children start the Child Sidebar Menu
147
  if( $result != FALSE ){
148
  echo '<ul class="child-sidebar-menu">';
149
+
150
  #-- If they want all the pages displayed always
151
  if( $instance['display_all'] == 'checked' ){
152
  wp_list_pages("sort_column=menu_order&title_li=&echo=1&child_of=".$p."&depth=".$instance['levels']."&exclude=".$instance['exclude']);
153
  } else {
154
+
155
  #-- Display children of current page's parent only
156
  foreach($result as $pID){
157
+
158
  #-- If the page is not in the excluded ones
159
  if( !in_array($pID->ID, $exclude) ){
160
  #--echo the current page from the $result
161
  wp_list_pages("sort_column=menu_order&title_li=&echo=1&depth=1&include=".$pID->ID);
162
  }
163
+
164
  #-- if the link that was just listed is the current page we are on
165
  if($pID->ID == $post->ID or $pID->ID == $post->post_parent or @in_array($pID->ID, $post->ancestors) ){
166
+
167
  $kids = $wpdb->get_results( "SELECT ID FROM ".$table_prefix."posts WHERE post_parent = ".$pID->ID." AND post_type='page' " );
168
  if( $kids != FALSE ){
169
+
170
  #-- Create a new menu with all the children under it
171
  echo '<ul class="grandchild-sidebar-menu">';
172
 
173
  wp_list_pages("sort_column=menu_order&title_li=&echo=1&exclude=".$instance['exclude']."&depth=3&child_of=".$pID->ID);
174
+
175
  echo '</ul>';
176
  }
177
  }
178
  }
179
  }
180
+
181
  #-- Close the First Level menu
182
  echo '</ul><!-- End child-sidebar-menu -->';
183
+
184
  }
185
  #-- If there was a menu close it off
186
  if($result != false || $instance['include_childless_parent'] == 'checked' ){
187
+
188
  echo '</ul></div><!-- end of very-custom-menu -->';
189
  }
190
+
191
  } #== /widget()
192
+
193
  } #== /Class
readme.txt CHANGED
@@ -4,8 +4,8 @@ Donate link: http://lipeimagination.info/contact/
4
  Tags: menus, sidebar menu, heirchy
5
  Requires at least: 3.1
6
  Tested up to: 3.2.1
7
- Stable tag: 2.0
8
- Version: 2.0
9
 
10
  == Description ==
11
 
4
  Tags: menus, sidebar menu, heirchy
5
  Requires at least: 3.1
6
  Tested up to: 3.2.1
7
+ Stable tag: 2.0.1
8
+ Version: 2.0.1
9
 
10
  == Description ==
11
 
screenshot-1.PNG CHANGED
Binary file