Advanced Sidebar Menu - Version 2.0.0

Version Description

Download this release

Release Info

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

Code changes from version 1.5.0 to 2.0.0

advanced-sidebar-menu.js ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <!-- Added this tag for easy includes -->
3
+ <script type="text/javascript">
4
+ //This will change the style display to block
5
+ //For the element that is sent to it
6
+ //Use the id or inline tags for this
7
+ function reveal_element( this_element_id ){
8
+ //If the toggle has already been clicked to show
9
+ //This will hide it
10
+ if( document.getElementById( this_element_id ).style.display == 'none' ){
11
+ document.getElementById( this_element_id ).style.display = 'block';
12
+ //If the toggle has already been clicked to hide
13
+ //This will show it
14
+ } else {
15
+ document.getElementById( this_element_id ).style.display = 'none';
16
+ }
17
+ }
18
+
19
+ </script>
advanced-sidebar-menu.php CHANGED
@@ -1,17 +1,17 @@
1
  <?php
2
  /*
3
  Plugin Name: Advanced Sidebar Menu
4
- Plugin URI: http://www.vimm.com
5
  Description: Creates dynamic menu based on child/parent relationship.
6
  Author: Mat Lipe
7
- Version: 1.5
8
- Author URI: http://www.vimm.com
9
-
10
- email: mat@lipeimagination.info
11
 
12
  */
13
 
14
- // register FooWidget widget
15
  add_action( 'widgets_init', create_function( '', 'return register_widget("advanced_sidebar_menu");' ) );
16
 
17
  class advanced_sidebar_menu extends WP_Widget {
@@ -19,9 +19,11 @@ class advanced_sidebar_menu extends WP_Widget {
19
  #-----------------------------------------------------------------------------------------------------------------------------------
20
  // this creates the widget form for the dashboard
21
  function form( $instance ) {
22
-
23
  ?>
24
 
 
 
25
  <p> Include Parent Page <input id="<?php echo $this->get_field_name('include_parent'); ?>"
26
  name="<?php echo $this->get_field_name('include_parent'); ?>" type="checkbox" value="checked"
27
  <?php echo $instance['include_parent']; ?>/></p>
@@ -30,7 +32,32 @@ class advanced_sidebar_menu extends WP_Widget {
30
  <p> Include Parent Even With No Children<input id="<?php echo $this->get_field_name('include_childless_parent'); ?>"
31
  name="<?php echo $this->get_field_name('include_childless_parent'); ?>" type="checkbox" value="checked"
32
  <?php echo $instance['include_childless_parent']; ?>/></p>
33
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
35
 
36
  #------------------------------------------------------------------------------------------------------------------------------
@@ -40,6 +67,9 @@ class advanced_sidebar_menu extends WP_Widget {
40
  $instance = $old_instance;
41
  $instance['include_childless_parent'] = strip_tags($new_instance['include_childless_parent']);
42
  $instance['include_parent'] = strip_tags($new_instance['include_parent']);
 
 
 
43
  return $instance;
44
  }
45
 
@@ -63,10 +93,14 @@ class advanced_sidebar_menu extends WP_Widget {
63
  global $wpdb;
64
  global $p;
65
  global $post;
 
 
 
66
 
67
 
68
  #-- if the post has parrents
69
  if($post->ancestors){
 
70
  $parent = $wpdb->get_var( "SELECT post_parent from wp_posts WHERE ID=".$post->ID );
71
 
72
  //--- If there is a parent of the post set $p to it and check if there is a parent as well
@@ -97,8 +131,12 @@ class advanced_sidebar_menu extends WP_Widget {
97
  #-- if the checkbox to include parent is checked
98
  if( $instance['include_parent'] == 'checked' ){
99
  $parent_toggle = TRUE;
100
- #-- list the parent page
101
- wp_list_pages("sort_column=menu_order&title_li=&echo=1&depth=1&include=".$p);
 
 
 
 
102
 
103
  }
104
  }
@@ -108,28 +146,37 @@ class advanced_sidebar_menu extends WP_Widget {
108
  //If there are children start the Child Sidebar Menu
109
  if( $result != FALSE ){
110
  echo '<ul class="child-sidebar-menu">';
 
 
 
 
 
111
 
112
- foreach($result as $pID){
113
-
114
 
115
- #--echo the current page from the $result
116
- wp_list_pages("sort_column=menu_order&title_li=&echo=1&depth=1&include=".$pID->ID);
 
 
 
117
 
118
- #-- if the link that was just listed is the current page we are on
119
- if($pID->ID == $post->ID or $pID->ID == $post->post_parent or @in_array($pID->ID, $post->ancestors) ){
120
 
121
- $kids = $wpdb->get_results( "SELECT ID FROM ".$table_prefix."posts WHERE post_parent = ".$pID->ID." AND post_type='page' " );
122
- if( $kids != FALSE ){
123
 
124
- #-- Create a new menu with all the children under it
125
- echo '<ul class="grandchild-sidebar-menu">';
126
 
127
- wp_list_pages("sort_column=menu_order&title_li=&echo=1&depth=3&child_of=".$pID->ID);
128
 
129
- echo '</ul>';
 
130
  }
131
- }
132
- }
133
 
134
  #-- Close the First Level menu
135
  echo '</ul><!-- End child-sidebar-menu -->';
1
  <?php
2
  /*
3
  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
11
 
12
  */
13
 
14
+ #-- Register the Widget
15
  add_action( 'widgets_init', create_function( '', 'return register_widget("advanced_sidebar_menu");' ) );
16
 
17
  class advanced_sidebar_menu extends WP_Widget {
19
  #-----------------------------------------------------------------------------------------------------------------------------------
20
  // this creates the widget form for the dashboard
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>
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
 
63
  #------------------------------------------------------------------------------------------------------------------------------
67
  $instance = $old_instance;
68
  $instance['include_childless_parent'] = strip_tags($new_instance['include_childless_parent']);
69
  $instance['include_parent'] = strip_tags($new_instance['include_parent']);
70
+ $instance['exclude'] = strip_tags($new_instance['exclude']);
71
+ $instance['display_all'] = strip_tags($new_instance['display_all']);
72
+ $instance['levels'] = strip_tags($new_instance['levels']);
73
  return $instance;
74
  }
75
 
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
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
  }
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 -->';
readme.txt CHANGED
@@ -4,13 +4,19 @@ 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: 1.5
8
- Version: 1.5
9
 
10
  == Description ==
11
 
12
- Creates a widget that can be dragged into a sidebar which automatically generates a menu based on the parent/child relationship of the pages. When on a top level page it displays a menu of the all of the top level pages and a menu of all of the pages that are children of the current page. Keep the sidebar menu clean and usable.
13
- Has a checkbox for including the top level of pages (good for sites that have 3 or more page levels) and a box to exclude pages and children of excluded page.
 
 
 
 
 
 
14
 
15
 
16
  == Installation ==
@@ -35,11 +41,19 @@ Yes. Based on whatever parents and children pages you are on, the menu will chan
35
 
36
  = How does this work with styling the page? =
37
 
38
- As of version 1.1 this will automatically generate class names for each level for menu system. You can add classes to your theme's style.css file to style it accourdingly. You may want to use something like margins to set the levels apart.
 
 
39
 
40
 
41
  == Changelog ==
42
 
 
 
 
 
 
 
43
  = 1.4.5 =
44
  * Added compatibility for sites with non wp_ prefix tables
45
  * Removed All traces of Each menu level if no pages to list
@@ -63,11 +77,19 @@ As of version 1.1 this will automatically generate class names for each level fo
63
  = 1.1 =
64
  * Added support for separate css classes on each level of the menu.
65
 
 
 
 
 
66
  == Upgrade Notice ==
67
 
 
 
 
 
68
  = 1.2 =
69
  This Version will allow you to order the pages in the menu using the page order section of the editor.
70
 
71
  = 1.1 =
72
- This version will allow simlier css styling.
73
 
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
 
12
+ Creates a widget that can be dragged into a sidebar which automatically generates a menu based on the parent/child relationship
13
+ of the pages. When on a top level page, it displays a menu of the all of the top level pages and a menu of all of the pages that
14
+ are children of the current page. Keeps the sidebar menu clean and usable.
15
+
16
+ Has the ability to exclude page from the menu.
17
+ As of 2.0 it also allows for display of all the child pages always.
18
+ You may also select the level of pages to display with this option
19
+
20
 
21
 
22
  == Installation ==
41
 
42
  = How does this work with styling the page? =
43
 
44
+ As of version 1.1 this will automatically generate class names for each level for menu system.
45
+ You can add classes to your theme's style.css file to style it accordingly.
46
+ You may want to use something like margins to set the levels apart.
47
 
48
 
49
  == Changelog ==
50
 
51
+ = 2.0 =
52
+ * Brought back the ability to exclude pages with support for excluding single pages from the menu.
53
+ * Added the ability to display all levels of child pages always.
54
+ * Added the option to select how many levels of pages to display when the "Always Display Child Pages" is selected
55
+
56
+
57
  = 1.4.5 =
58
  * Added compatibility for sites with non wp_ prefix tables
59
  * Removed All traces of Each menu level if no pages to list
77
  = 1.1 =
78
  * Added support for separate css classes on each level of the menu.
79
 
80
+
81
+ == Screenshots ==
82
+ 1. The widget Menu as of 2.0
83
+
84
  == Upgrade Notice ==
85
 
86
+ = 2.0 =
87
+ This Version will give you better control over the menu and styling ability.
88
+ Added new options and more stable code.
89
+
90
  = 1.2 =
91
  This Version will allow you to order the pages in the menu using the page order section of the editor.
92
 
93
  = 1.1 =
94
+ This version will allow simliar css styling.
95
 
screenshot-1.PNG CHANGED
Binary file