Advanced Sidebar Menu - Version 3.0.0

Version Description

Download this release

Release Info

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

Code changes from version 3.2.3 to 3.0.0

advanced-sidebar-menu.php CHANGED
@@ -4,27 +4,23 @@ Plugin Name: Advanced Sidebar Menu
4
  Plugin URI: http://lipeimagination.info/wordpress/advanced-sidebar-menu/
5
  Description: Creates dynamic menu based on child/parent relationship.
6
  Author: Mat Lipe
7
- Version: 3.2.3
8
  Author URI: http://lipeimagination.info
9
- Since: 6/4/12
10
  Email: mat@lipeimagination.info
11
-
12
  */
13
 
14
-
15
  #-- Bring in the functions
16
  require( 'functions.php' );
17
  $asm = new advanced_sidebar_menu_functions();
18
 
19
- #-- Version 3.2 notice
20
- add_action( 'init', array( $asm, 'validate_3_2' ) );
21
-
22
 
23
 
24
  #-- Bring in the Widgets
25
  require( 'widgets/init.php' );
26
 
27
-
28
  #-- Define Constants
29
  define( 'ADVANCED_SIDEBAR_WIDGETS_DIR', plugin_dir_path(__FILE__) . 'widgets/' );
30
  define( 'ADVANCED_SIDEBAR_VIEWS_DIR', plugin_dir_path(__FILE__) . 'views/' );
4
  Plugin URI: http://lipeimagination.info/wordpress/advanced-sidebar-menu/
5
  Description: Creates dynamic menu based on child/parent relationship.
6
  Author: Mat Lipe
7
+ Version: 3.3.0
8
  Author URI: http://lipeimagination.info
9
+ Since: 7/16/12
10
  Email: mat@lipeimagination.info
 
11
  */
12
 
 
13
  #-- Bring in the functions
14
  require( 'functions.php' );
15
  $asm = new advanced_sidebar_menu_functions();
16
 
17
+ //Validate the new version
18
+ add_action( 'init', array( $asm, 'validate_3_3' ) );
 
19
 
20
 
21
  #-- Bring in the Widgets
22
  require( 'widgets/init.php' );
23
 
 
24
  #-- Define Constants
25
  define( 'ADVANCED_SIDEBAR_WIDGETS_DIR', plugin_dir_path(__FILE__) . 'widgets/' );
26
  define( 'ADVANCED_SIDEBAR_VIEWS_DIR', plugin_dir_path(__FILE__) . 'views/' );
functions.php CHANGED
@@ -4,68 +4,53 @@
4
  /**
5
  * These Functions are Specific to the Advanced Sidebar Menu
6
  * @author Mat Lipe
7
- * @since 6/3/12
8
  */
9
 
10
 
11
 
12
  class advanced_sidebar_menu_functions{
13
- protected $bad = array(); //for 3.2 version
14
- protected $cat_file = ''; //for 3.2 version
15
 
16
 
17
  /**
18
  * Validate the views for the new structure
19
- * @since 6/3/12
20
  */
21
- function validate_3_2(){
22
-
23
-
24
  /** Note to self -- Remove this at the new version **/
25
- if ( $cat_file = locate_template(array('advanced-sidebar-menu/category_list.php')) ) {
26
-
27
- $data = explode("\n", file_get_contents( $cat_file )); //create array separate by new line
28
-
29
- //print_r( $data );
30
-
31
  foreach( $data as $line => $content ){
32
-
33
  $line++;
34
-
35
- if( strpos( $content, " class=\"advanced-sidebar-menu widget advanced-sidebar-category\">" ) ){
36
  $bad[$line] = htmlentities( $content );
37
  }
38
-
39
- if( strpos( $content, "<div class=\"widget-wrap\">';" ) ){
40
  $bad[$line] = htmlentities( $content );
41
  }
42
-
43
-
44
- if( strpos( $content, "</div></div><!-- END #advanced-sidebar-cat-menu -->';" ) ){
45
 
46
  $bad[$line] = htmlentities( $content );
47
  }
48
-
49
  }
50
-
51
  if( !empty( $bad ) ){
52
  $this->bad = $bad;
53
- $this->cat_file = get_bloginfo( 'stylesheet_directory' ) . 'advanced-sidebar-menu/category_list.php';
54
- add_action( 'admin_notices', array( $this, 'notice_3_2') );
55
  }
56
-
57
  }
58
-
59
  }
60
 
61
 
62
  /**
63
  * Adds an admin notice if there are issues with the view
64
- * @since 6/3/12
65
  */
66
- function notice_3_2( ){
67
  echo '<div class="error">';
68
- echo 'To use version 3.2 of <b>Advanced Sidebar Menu</b> you must delete the following lines from <b>"' . $this->cat_file . '"</b><br>';
69
 
70
  foreach( $this->bad as $line => $content ){
71
  echo '<b>line' . $line . ': </b> '. $content . '<br>';
@@ -74,26 +59,160 @@ function notice_3_2( ){
74
  echo '</div>';
75
 
76
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
 
79
-
80
-
81
-
82
- /**
83
- * Allows for Overwritting files in the child theme
84
- * @since 6/3/12
85
- */
86
 
87
- static function file_hyercy( $file ){
 
 
 
 
 
 
88
 
89
- if ( $theme_file = locate_template(array('advanced-sidebar-menu/'.$file)) ) {
90
- $file = $theme_file;
91
- } else {
92
- $file = ADVANCED_SIDEBAR_VIEWS_DIR . $file;
93
  }
94
- return $file;
95
-
96
- }
97
 
98
  } //End class
99
 
4
  /**
5
  * These Functions are Specific to the Advanced Sidebar Menu
6
  * @author Mat Lipe
7
+ * @since 7/16/12
8
  */
9
 
10
 
11
 
12
  class advanced_sidebar_menu_functions{
13
+ protected $bad = array(); //for 3.3 version
14
+ protected $bad_file = ''; //for 3.3 version
15
 
16
 
17
  /**
18
  * Validate the views for the new structure
19
+ * @since 7/16/12
20
  */
21
+ function validate_3_3(){
 
 
22
  /** Note to self -- Remove this at the new version **/
23
+ if ( $page_file = locate_template(array('advanced-sidebar-menu/page_list.php')) ) {
24
+ $data = explode("\n", file_get_contents( $page_file )); //create array separate by new line
 
 
 
 
25
  foreach( $data as $line => $content ){
 
26
  $line++;
27
+ if( strpos( $content, 'class="advanced-sidebar-menu widget advanced-sidebar-page">' ) ){
 
28
  $bad[$line] = htmlentities( $content );
29
  }
30
+ if( strpos( $content, "<div class=\"widget-wrap\">" ) ){
 
31
  $bad[$line] = htmlentities( $content );
32
  }
33
+ if( strpos( $content, "</div></div><!-- end of very-custom-menu -->" ) ){
 
 
34
 
35
  $bad[$line] = htmlentities( $content );
36
  }
 
37
  }
 
38
  if( !empty( $bad ) ){
39
  $this->bad = $bad;
40
+ $this->bad_file = get_bloginfo( 'stylesheet_directory' ) . '/advanced-sidebar-menu/page_list.php';
41
+ add_action( 'admin_notices', array( $this, 'notice_3_3') );
42
  }
 
43
  }
 
44
  }
45
 
46
 
47
  /**
48
  * Adds an admin notice if there are issues with the view
49
+ * @since 7/16/12
50
  */
51
+ function notice_3_3( ){
52
  echo '<div class="error">';
53
+ echo 'To use version 3.3 of <b>Advanced Sidebar Menu</b> you must delete the following lines from <b>"' . $this->bad_file . '"</b><br>';
54
 
55
  foreach( $this->bad as $line => $content ){
56
  echo '<b>line' . $line . ': </b> '. $content . '<br>';
59
  echo '</div>';
60
 
61
  }
62
+
63
+
64
+
65
+
66
+
67
+ private $instance; //The widget instance
68
+ private $top_id; //Either the top cat or page
69
+ private $exclude;
70
+ private $ancestors; //For the category ancestors
71
+
72
+ /**
73
+ * Sets the instance of this widget to this class
74
+ * @param array $instance the widgets instance
75
+ * @since 7/16/12
76
+ */
77
+ function set_widget_vars( $instance, $top_id, $exclude, $ancestors = array() ){
78
+ $this->instance = $instance;
79
+ $this->top_id = $top_id;
80
+ $this->exclude = $exclude;
81
+ $this->ancestors = $ancestors;
82
+ }
83
+
84
+ /**
85
+ *
86
+ * IF this is a top level category
87
+ * @param obj $cat the cat object
88
+ */
89
+ function first_level_category( $cat ){
90
+ if( !in_array($cat->cat_ID, $this->exclude) && $cat->parent == $this->top_id){
91
+ return true;
92
+ } else {
93
+ return false;
94
+ }
95
+ }
96
+
97
+ /**
98
+ * If the cat is a second level cat
99
+ * @param obj $cat the cat
100
+ * @since 7/16/12
101
+ */
102
+ function second_level_cat( $cat ){
103
+ //if this is the currrent cat or a parent of the current cat
104
+ if( $cat->cat_ID == get_query_var('cat' ) || in_array( $cat->cat_ID, $this->ancestors )){
105
+ $all_children = array();
106
+ $all_children = get_categories( array( 'child_of' => $child_cat->cat_ID ) );
107
+ if( !empty( $all_children ) ){
108
+ return true;
109
+ } else {
110
+ return false;
111
+ }
112
+
113
+ } else {
114
+ return false;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Determines if all the children should be included
120
+ * @since 7/16/12
121
+ * @return bool
122
+ */
123
+ function display_all(){
124
+ if( $this->instance['display_all'] == 'checked' ){
125
+ return true;
126
+ } else {
127
+ return false;
128
+ }
129
+ }
130
+
131
+ /**
132
+ *
133
+ * Returns and array of all the children of a page
134
+ * @param int $pID the id of the page
135
+ * @since 7/19/12
136
+ */
137
+ function page_children( $pID ){
138
+ global $wpdb, $table_prefix;
139
+ return $wpdb->get_results( "SELECT ID FROM ".$table_prefix."posts WHERE post_parent = ".$pID." AND post_type='page' AND post_status='publish'" );
140
+
141
+ }
142
+
143
+ /**
144
+ *
145
+ * Determines if this is an ancestor or the current post
146
+ * @param obj $pID the post object
147
+ * @since 7/19/12
148
+ */
149
+ function page_ancestor( $pID ){
150
+ global $post;
151
+ if($pID->ID == $post->ID or $pID->ID == $post->post_parent or @in_array($pID->ID, $post->ancestors) ){
152
+ return true;
153
+ } else {
154
+ return false;
155
+ }
156
+ }
157
+
158
+
159
+ /**
160
+ * Determines if the parent page or cat should be included
161
+ * @since 7/16/12
162
+ * @return bool
163
+ */
164
+ function include_parent(){
165
+ if( ($this->instance['include_parent'] == 'checked') && (!in_array($this->top_id, $this->exclude)) ){
166
+ return true;
167
+ } else {
168
+ return false;
169
+ }
170
+ }
171
+
172
+
173
+ /**
174
+ * Echos the title of the widget to the page
175
+ * @since 7/16/12
176
+ */
177
+ function title(){
178
+ if( $this->instance['title'] != '' ){
179
+ echo '<h4 class="widgettitle">' . $this->instance['title'] . '</h4>';
180
+ }
181
+
182
+ }
183
+
184
+
185
+ /**
186
+ *
187
+ * Checks is this id is excluded or not
188
+ * @param int $id the id to check
189
+ * @return bool
190
+ */
191
+ function exclude( $id ){
192
+ if( !in_array( $id, $this->exclude ) ){
193
+ return true;
194
+ } else {
195
+ return false;
196
+ }
197
+ }
198
+
199
 
200
 
201
+ /**
202
+ * Allows for Overwritting files in the child theme
203
+ * @since 6/3/12
204
+ * @param string $file the name of the file to overwrite
205
+ */
 
 
206
 
207
+ static function file_hyercy( $file ){
208
+ if ( $theme_file = locate_template(array('advanced-sidebar-menu/'.$file)) ) {
209
+ $file = $theme_file;
210
+ } else {
211
+ $file = ADVANCED_SIDEBAR_VIEWS_DIR . $file;
212
+ }
213
+ return $file;
214
 
 
 
 
 
215
  }
 
 
 
216
 
217
  } //End class
218
 
readme.txt CHANGED
@@ -3,26 +3,38 @@ Contributors: Mat Lipe
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40lipeimagination%2einfo&lc=US&item_name=Advanced%20Sidebar%20Menu&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest
4
  Tags: menus, sidebar menu, heirchy, category menu, pages menu
5
  Requires at least: 3.1
6
- Tested up to: 3.3.2
7
- Stable tag: 3.2.3
8
- Version: 3.2.3
9
 
10
  == Description ==
11
 
12
- Creates a widget that automatically generates a menu based on the parent/child relationship of pages.
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
- As of Version 3.2 you have the option to display the categories on single post page when using the categories widget.
17
-
18
-
19
- As of Version 3.0 it also creates a widget that does the same functionality for Categories.
20
-
21
- Has the ability to exclude page from the menu.
22
- As of 2.0 it also allows for display of all the child pages always.
23
- You may also select the level of pages to display with this option.
24
-
25
-
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
 
28
  == Installation ==
@@ -64,6 +76,13 @@ You may want to use something like margins to set the levels apart.
64
 
65
 
66
  == Changelog ==
 
 
 
 
 
 
 
67
 
68
  = 3.2.3 =
69
  * Fix a bug that caused multiple category list to display of more than one category the single post was in shared the same parent
@@ -118,12 +137,14 @@ You may want to use something like margins to set the levels apart.
118
  * Added support for separate css classes on each level of the menu.
119
 
120
 
121
- == Screenshots ==
122
-
123
- 1. The widget Menu as of 2
124
 
125
  == Upgrade Notice ==
126
 
 
 
 
 
 
127
  = 3.2.3 =
128
  This will add the ability to display the categories on single post pages.
129
  If you are using the category_list.php view you will most likely get an error message to remove a couple lines.
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40lipeimagination%2einfo&lc=US&item_name=Advanced%20Sidebar%20Menu&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest
4
  Tags: menus, sidebar menu, heirchy, category menu, pages menu
5
  Requires at least: 3.1
6
+ Tested up to: 3.4.1
7
+ Stable tag: 3.3.0
8
+ Version: 3.3.0
9
 
10
  == Description ==
11
 
12
+ Creates a widget for both page and categories that will display the current page/category and an child pages or categories.
13
+ Keeps the menu clean and usable.
14
+
15
+ Includes Page options:
16
+ 1. Add a title to the widget
17
+ 2. Include the highest level parent page
18
+ 3. Include the highest level parent page even with no Children
19
+ 4. Use built in styling (very plain styling currently but plans for more advanced in near future versions)
20
+ 5. Exclude pages
21
+ 6. Always display child Pages
22
+ 7. Number of levels of child pages to display
23
+
24
+ Includes Category Options:
25
+ 1. Add a title to the widget
26
+ 2. Include Parent Category
27
+ 3. Include Parent Even with no Children
28
+ 4. Use Built in Styling
29
+ 5. Display Categories on Single Posts
30
+ 6. To display each Single Posts Category in a new widget or in same list
31
+ 7. Exclude Categories
32
+ 8. Always display child categories
33
+ 9. Levels of Categories to display
34
+
35
+
36
+ There is also built in functionality to overright the output of the widgets and the css to customize this and still be upgrade safe.
37
+
38
 
39
 
40
  == Installation ==
76
 
77
 
78
  == Changelog ==
79
+ = 3.3.0 =
80
+ * Added the ability to have a widget title
81
+ * Redesigned the entire structure to prepare for future changes
82
+
83
+
84
+ = 3.2.5 =
85
+ * Bugfixes
86
 
87
  = 3.2.3 =
88
  * Fix a bug that caused multiple category list to display of more than one category the single post was in shared the same parent
137
  * Added support for separate css classes on each level of the menu.
138
 
139
 
 
 
 
140
 
141
  == Upgrade Notice ==
142
 
143
+ = 3.3.0 =
144
+ If you customized the output previously you may want to redo it on this version to take advantage of the new structure.
145
+ IF you are are using the page_list.php view you will most likely get an error message to remove a couple lines.
146
+ These lines are no longer needed for the structure in this version.
147
+
148
  = 3.2.3 =
149
  This will add the ability to display the categories on single post pages.
150
  If you are using the category_list.php view you will most likely get an error message to remove a couple lines.
views/category_list.php CHANGED
@@ -3,56 +3,52 @@
3
  /**
4
  * The Ouput of tad Advanced Sidebar Categories Widget
5
  * @author Mat Lipe
6
- * @since 6/3/12
7
  *
8
  *
9
  * @uses to edit create a file named category_list.php and put in a folder in the your child theme called 'advanced-sidebar-menu
10
  * @uses copy the contents of the file into that file and edit at will
11
- * @param Do not edit this file or it will break on update
12
  */
13
 
14
 
 
 
15
 
16
- #-- if the checkbox to include parent is checked
17
- if( $instance['include_parent'] == 'checked' && !in_array($top_cat, $exclude) ){
18
-
19
- echo '<ul class="parent-sidebar-menu">';
20
- wp_list_categories( 'title_li=&include=' . $top_cat);
21
-
22
- $parent = 'yes';
23
- }
24
-
25
- if( !empty($all) ){
26
-
27
  echo '<ul class="child-sidebar-menu">';
28
 
29
  #-- If they want all the child categories displayed always
30
- if( $instance['display_all'] == 'checked' ){
31
  wp_list_categories('title_li=&child_of=' . $top_cat .'&depth=' .$instance['levels'] );
32
- echo '</ul><!-- End #child-sidebar-menu -->';
 
33
  } else {
34
-
35
- foreach( $all as $child_cat ){
36
-
37
- if( !in_array($child_cat->cat_ID, $exclude) && $child_cat->parent == $top_cat){
38
-
 
 
39
  //List the child category and the children if it is the current one
40
  wp_list_categories('title_li=&include=' . $child_cat->cat_ID . '&depth=1' );
41
 
42
- if( $child_cat->cat_ID == get_query_var('cat' ) || in_array( $child_cat->cat_ID, $cat_ancestors ) ){
43
-
44
- $all_children = array();
45
- $all_children = get_categories( array( 'child_of' => $child_cat->cat_ID ) );
46
-
47
- if( !empty( $all_children ) ){
48
  #-- Create a new menu with all the children under it
49
  echo '<ul class="grandchild-sidebar-menu">';
50
-
51
- wp_list_categories("title_li=&exclude=".$instance['exclude']."&depth=3&child_of=" .$child_cat->cat_ID );
52
-
53
  echo '</ul>';
54
- }
55
- }
56
  }
57
  } //End foreach
58
 
@@ -60,18 +56,10 @@
60
 
61
  } //End if display all is not checked
62
 
63
-
64
  } //End if the are child categories
65
 
66
 
67
  #-- if a parent category was displayed
68
- if( isset($parent) ){
69
  echo '</ul><!-- End #parent-sidebar-menu -->';
70
-
71
- unset( $parent); //for next time
72
- }
73
-
74
-
75
-
76
-
77
-
3
  /**
4
  * The Ouput of tad Advanced Sidebar Categories Widget
5
  * @author Mat Lipe
6
+ * @since 7/16/12
7
  *
8
  *
9
  * @uses to edit create a file named category_list.php and put in a folder in the your child theme called 'advanced-sidebar-menu
10
  * @uses copy the contents of the file into that file and edit at will
11
+ * @param Do not edit this file in this location or it will break on update
12
  */
13
 
14
 
15
+ //Displays the title
16
+ $asm->title();
17
 
18
+ //Include the parent page if chosen
19
+ if( $asm->include_parent() ){
20
+ echo '<ul class="parent-sidebar-menu">';
21
+ wp_list_categories( 'title_li=&include=' . $top_cat);
22
+ }
23
+ //If there are children to display
24
+ if( !empty($all_categories) ){
 
 
 
 
25
  echo '<ul class="child-sidebar-menu">';
26
 
27
  #-- If they want all the child categories displayed always
28
+ if( $asm->display_all() ){
29
  wp_list_categories('title_li=&child_of=' . $top_cat .'&depth=' .$instance['levels'] );
30
+ echo '</ul><!-- End #child-sidebar-menu -->';
31
+
32
  } else {
33
+
34
+ #-- to Display the categories based a parent child relationship
35
+ foreach( $all_categories as $child_cat ){
36
+
37
+ //IF this is a child category of the top one
38
+ if( $asm->first_level_category( $child_cat ) ){
39
+
40
  //List the child category and the children if it is the current one
41
  wp_list_categories('title_li=&include=' . $child_cat->cat_ID . '&depth=1' );
42
 
43
+
44
+ //If there are children of this cat and it is a parent or child or the current cat
45
+ if( $asm->second_level_cat( $child_cat ) ){
 
 
 
46
  #-- Create a new menu with all the children under it
47
  echo '<ul class="grandchild-sidebar-menu">';
48
+ wp_list_categories("title_li=&exclude=".$instance['exclude']."&depth=3&child_of=" .$child_cat->cat_ID );
 
 
49
  echo '</ul>';
50
+
51
+ }
52
  }
53
  } //End foreach
54
 
56
 
57
  } //End if display all is not checked
58
 
 
59
  } //End if the are child categories
60
 
61
 
62
  #-- if a parent category was displayed
63
+ if( $asm->include_parent() ){
64
  echo '</ul><!-- End #parent-sidebar-menu -->';
65
+ }
 
 
 
 
 
 
 
views/page_list.php CHANGED
@@ -5,68 +5,50 @@
5
  /**
6
  * The Ouput of tad Advanced Sidebar Page Widget
7
  * @author Mat Lipe
8
- * @since 4/13/12
9
  *
10
  *
11
- * @uses to edit create a file named page_list.php and put in a folder in the your child theme called 'advanced-sidebar-menu
12
  * @uses copy the contents of the file into that file and edit at will
13
- * @param Do not edit this file or it will break on upgrade
14
  */
15
 
 
16
 
17
-
18
-
19
-
20
-
21
- //Start the menu
22
- echo '<div id="'.$args['widget_id'].'" class="advanced-sidebar-menu widget advanced-sidebar-page">
23
- <div class="widget-wrap">';
24
-
25
-
26
- #-- if the checkbox to include parent is checked
27
- if( $instance['include_parent'] == 'checked' ){
28
- echo '<ul class="parent-sidebar-menu" >';
29
-
30
- $parent_toggle = TRUE;
31
-
32
- #-- If the page is not excluded from the menu
33
- if( !in_array($p, $exclude) ){
34
- #-- list the parent page
35
- wp_list_pages("sort_column=menu_order&title_li=&echo=1&depth=1&include=".$p);
36
- }
37
-
38
- }
39
-
40
-
41
 
42
 
43
  //If there are children start the Child Sidebar Menu
44
- if( $result != FALSE ){
45
  echo '<ul class="child-sidebar-menu">';
46
 
47
  #-- If they want all the pages displayed always
48
- if( $instance['display_all'] == 'checked' ){
49
- wp_list_pages("sort_column=menu_order&title_li=&echo=1&child_of=".$p."&depth=".$instance['levels']."&exclude=".$instance['exclude']);
 
50
  } else {
51
 
52
  #-- Display children of current page's parent only
53
  foreach($result as $pID){
54
 
55
  #-- If the page is not in the excluded ones
56
- if( !in_array($pID->ID, $exclude) ){
57
  #--echo the current page from the $result
58
  wp_list_pages("sort_column=menu_order&title_li=&echo=1&depth=1&include=".$pID->ID);
59
  }
60
 
61
  #-- if the link that was just listed is the current page we are on
62
- if($pID->ID == $post->ID or $pID->ID == $post->post_parent or @in_array($pID->ID, $post->ancestors) ){
63
-
64
- $kids = $wpdb->get_results( "SELECT ID FROM ".$table_prefix."posts WHERE post_parent = ".$pID->ID." AND post_type='page' " );
65
- if( $kids != FALSE ){
66
 
 
 
 
67
  #-- Create a new menu with all the children under it
68
  echo '<ul class="grandchild-sidebar-menu">';
69
-
70
  wp_list_pages("sort_column=menu_order&title_li=&echo=1&exclude=".$instance['exclude']."&depth=3&child_of=".$pID->ID);
71
 
72
  echo '</ul>';
@@ -79,14 +61,10 @@ if( $result != FALSE ){
79
  echo '</ul><!-- End child-sidebar-menu -->';
80
 
81
  }
 
 
 
 
82
 
83
 
84
- #-- If there was a menu close it off
85
- if($result != false || $instance['include_childless_parent'] == 'checked' ){
86
-
87
- if( $instance['include_parent'] == 'checked' ) {
88
- echo '<ul>';
89
- }
90
- echo '</div></div><!-- end of very-custom-menu -->';
91
- }
92
 
5
  /**
6
  * The Ouput of tad Advanced Sidebar Page Widget
7
  * @author Mat Lipe
8
+ * @since 7/16/12
9
  *
10
  *
11
+ * @uses to edit, create a file named page_list.php and put in a folder in the your theme called 'advanced-sidebar-menu
12
  * @uses copy the contents of the file into that file and edit at will
13
+ * @uses Do not edit this file in its original location or it will break on upgrade
14
  */
15
 
16
+ $asm->title();
17
 
18
+ #-- list the parent page if chosen
19
+ if( $asm->include_parent() ){
20
+ echo '<ul class="parent-sidebar-menu" >';
21
+ wp_list_pages("sort_column=menu_order&title_li=&echo=1&depth=1&include=".$top_parent);
22
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
 
25
  //If there are children start the Child Sidebar Menu
26
+ if( $child_pages ){
27
  echo '<ul class="child-sidebar-menu">';
28
 
29
  #-- If they want all the pages displayed always
30
+ if( $asm->display_all() ){
31
+
32
+ wp_list_pages("sort_column=menu_order&title_li=&echo=1&child_of=".$top_parent."&depth=".$instance['levels']."&exclude=".$instance['exclude']);
33
  } else {
34
 
35
  #-- Display children of current page's parent only
36
  foreach($result as $pID){
37
 
38
  #-- If the page is not in the excluded ones
39
+ if( $asm->exclude( $pID->ID) ){
40
  #--echo the current page from the $result
41
  wp_list_pages("sort_column=menu_order&title_li=&echo=1&depth=1&include=".$pID->ID);
42
  }
43
 
44
  #-- if the link that was just listed is the current page we are on
45
+ if( $asm->page_ancestor( $pID ) ){
 
 
 
46
 
47
+ //Get the children of this page
48
+ $grandkids = $asm->page_children($pID->ID );
49
+ if( $grandkids ){
50
  #-- Create a new menu with all the children under it
51
  echo '<ul class="grandchild-sidebar-menu">';
 
52
  wp_list_pages("sort_column=menu_order&title_li=&echo=1&exclude=".$instance['exclude']."&depth=3&child_of=".$pID->ID);
53
 
54
  echo '</ul>';
61
  echo '</ul><!-- End child-sidebar-menu -->';
62
 
63
  }
64
+ if( $asm->include_parent() ) {
65
+ echo '</ul><!-- .parent-sidebar-menu -->';
66
+ }
67
+
68
 
69
 
 
 
 
 
 
 
 
 
70
 
widgets/category.widget.php CHANGED
@@ -20,7 +20,9 @@ class advanced_sidebar_menu_category extends WP_Widget {
20
  function form( $instance ) {
21
  // require( ADVANCED_SIDEBAR_DIR . 'advanced-sidebar-menu.js' );
22
  ?>
23
-
 
 
24
 
25
 
26
  <p> Include Parent Category <input id="<?php echo $this->get_field_name('include_parent'); ?>"
@@ -36,7 +38,7 @@ class advanced_sidebar_menu_category extends WP_Widget {
36
  name="<?php echo $this->get_field_name('css'); ?>" type="checkbox" value="checked"
37
  <?php echo $instance['css']; ?>/></p>
38
 
39
- <p> Display Categories on Single Post Page's <input id="<?php echo $this->get_field_name('single'); ?>"
40
  name="<?php echo $this->get_field_name('single'); ?>" type="checkbox" value="checked"
41
  onclick="javascript:asm_reveal_element( 'new-widget-<?php echo $this->get_field_name('new_widget'); ?>' )"
42
  <?php echo $instance['single']; ?>/></p>
@@ -105,6 +107,8 @@ class advanced_sidebar_menu_category extends WP_Widget {
105
  $instance['css'] = strip_tags($new_instance['css']);
106
  $instance['single'] = strip_tags($new_instance['single']); //Display on single pages
107
  $instance['new_widget'] = strip_tags($new_instance['new_widget']); //Create a new widget for each single category
 
 
108
  return $instance;
109
  }
110
 
@@ -124,6 +128,7 @@ class advanced_sidebar_menu_category extends WP_Widget {
124
 
125
  // adds the output to the widget area on the page
126
  function widget($args, $instance) {
 
127
  #-- Create a usable array of the excluded pages
128
  $exclude = explode(',', $instance['exclude']);
129
  $cat_ids = $already_top = array();
@@ -181,11 +186,13 @@ class advanced_sidebar_menu_category extends WP_Widget {
181
 
182
 
183
  //Check for children
184
- $all = get_categories( array( 'child_of' => $top_cat ) );
185
-
 
 
186
 
187
  //If there are any child categories or the include childless parent is checked
188
- if( !empty($all ) || ($instance['include_childless_parent'] == 'checked' && !in_array($top_cat, $exclude)) ){
189
 
190
 
191
  //Creates a new widget for each category the single page has if the options are selected to do so
@@ -204,8 +211,9 @@ class advanced_sidebar_menu_category extends WP_Widget {
204
  }
205
 
206
 
 
207
  //Bring in the view
208
- require( advanced_sidebar_menu_functions::file_hyercy( 'category_list.php' ) );
209
 
210
 
211
  if( $close ){
20
  function form( $instance ) {
21
  // require( ADVANCED_SIDEBAR_DIR . 'advanced-sidebar-menu.js' );
22
  ?>
23
+ <p> Title <br>
24
+ <input id="<?php echo $this->get_field_name('title'); ?>"
25
+ name="<?php echo $this->get_field_name('title'); ?>" size="50" type="text" value="<?php echo $instance['title']; ?>"/></p>
26
 
27
 
28
  <p> Include Parent Category <input id="<?php echo $this->get_field_name('include_parent'); ?>"
38
  name="<?php echo $this->get_field_name('css'); ?>" type="checkbox" value="checked"
39
  <?php echo $instance['css']; ?>/></p>
40
 
41
+ <p> Display Categories on Single Posts <input id="<?php echo $this->get_field_name('single'); ?>"
42
  name="<?php echo $this->get_field_name('single'); ?>" type="checkbox" value="checked"
43
  onclick="javascript:asm_reveal_element( 'new-widget-<?php echo $this->get_field_name('new_widget'); ?>' )"
44
  <?php echo $instance['single']; ?>/></p>
107
  $instance['css'] = strip_tags($new_instance['css']);
108
  $instance['single'] = strip_tags($new_instance['single']); //Display on single pages
109
  $instance['new_widget'] = strip_tags($new_instance['new_widget']); //Create a new widget for each single category
110
+ $instance['title'] = strip_tags($new_instance['title']);
111
+
112
  return $instance;
113
  }
114
 
128
 
129
  // adds the output to the widget area on the page
130
  function widget($args, $instance) {
131
+ global $asm;
132
  #-- Create a usable array of the excluded pages
133
  $exclude = explode(',', $instance['exclude']);
134
  $cat_ids = $already_top = array();
186
 
187
 
188
  //Check for children
189
+ $all_categories = get_categories( array( 'child_of' => $top_cat ) );
190
+
191
+ //for depreciation
192
+ $all = $all_categories;
193
 
194
  //If there are any child categories or the include childless parent is checked
195
+ if( !empty($all_categories ) || ($instance['include_childless_parent'] == 'checked' && !in_array($top_cat, $exclude)) ){
196
 
197
 
198
  //Creates a new widget for each category the single page has if the options are selected to do so
211
  }
212
 
213
 
214
+ $asm->set_widget_vars( $instance, $top_cat, $exclude, $cat_ancestors );
215
  //Bring in the view
216
+ require( $asm->file_hyercy( 'category_list.php' ) );
217
 
218
 
219
  if( $close ){
widgets/page.widget.php CHANGED
@@ -5,12 +5,13 @@
5
  * Creates a Widget of parent Child Pages
6
  *
7
  * @author mat lipe
8
- * @since 6/3/12
9
  * @package Advanced Sidebar Menu
10
  *
11
  */
12
 
13
 
 
14
  class advanced_sidebar_menu_page extends WP_Widget {
15
 
16
  #-----------------------------------------------------------------------------------------------------------------------------------
@@ -18,26 +19,28 @@ class advanced_sidebar_menu_page extends WP_Widget {
18
  function form( $instance ) {
19
  // require( ADVANCED_SIDEBAR_DIR . 'advanced-sidebar-menu.js' );
20
  ?>
21
-
22
-
23
-
24
- <p> Include Parent Page <input id="<?php echo $this->get_field_name('include_parent'); ?>"
 
 
25
  name="<?php echo $this->get_field_name('include_parent'); ?>" type="checkbox" value="checked"
26
  <?php echo $instance['include_parent']; ?>/></p>
27
 
28
 
29
- <p> Include Parent Even With No Children<input id="<?php echo $this->get_field_name('include_childless_parent'); ?>"
30
  name="<?php echo $this->get_field_name('include_childless_parent'); ?>" type="checkbox" value="checked"
31
  <?php echo $instance['include_childless_parent']; ?>/></p>
32
 
33
- <p> Use Built in Styling <input id="<?php echo $this->get_field_name('css'); ?>"
34
  name="<?php echo $this->get_field_name('css'); ?>" type="checkbox" value="checked"
35
  <?php echo $instance['css']; ?>/></p>
36
 
37
- <p> Pages to Exclude, Comma Separated:<input id="<?php echo $this->get_field_name('exclude'); ?>"
38
  name="<?php echo $this->get_field_name('exclude'); ?>" type="text" value="<?php echo $instance['exclude']; ?>"/></p>
39
 
40
- <p> Always Display Child Pages <input id="<?php echo $this->get_field_name('display_all'); ?>"
41
  name="<?php echo $this->get_field_name('display_all'); ?>" type="checkbox" value="checked"
42
  onclick="javascript:asm_reveal_element( 'levels-<?php echo $this->get_field_name('levels'); ?>' )"
43
  <?php echo $instance['display_all']; ?>/></p>
@@ -48,7 +51,7 @@ class advanced_sidebar_menu_page extends WP_Widget {
48
  } else {
49
  echo 'display:none';
50
  } ?>">
51
- <p> Levels to Display <select id="<?php echo $this->get_field_name('levels'); ?>"
52
  name="<?php echo $this->get_field_name('levels'); ?>">
53
  <?php
54
  for( $i= 1; $i<6; $i++ ){
@@ -72,6 +75,7 @@ class advanced_sidebar_menu_page extends WP_Widget {
72
  $instance['display_all'] = strip_tags($new_instance['display_all']);
73
  $instance['levels'] = strip_tags($new_instance['levels']);
74
  $instance['css'] = strip_tags($new_instance['css']);
 
75
  return $instance;
76
  }
77
 
@@ -81,10 +85,10 @@ class advanced_sidebar_menu_page extends WP_Widget {
81
  function advanced_sidebar_menu_page( ) {
82
  /* Widget settings. */
83
  $widget_ops = array( 'classname' => 'sidebar-menu', 'description' => 'Creates a menu of all the pages using the child/parent relationship' );
84
-
85
 
86
  /* Create the widget. */
87
- $this->WP_Widget( 'advanced_sidebar_menu', 'Advanced Sidebar Pages Menu', $widget_ops);
88
  }
89
 
90
 
@@ -92,58 +96,49 @@ class advanced_sidebar_menu_page extends WP_Widget {
92
 
93
  // adds the output to the widget area on the page
94
  function widget($args, $instance) {
 
 
95
 
96
- if( is_page() ){
97
-
98
- global $wpdb;
99
- global $p;
100
- global $post;
101
 
102
  #-- Create a usable array of the excluded pages
103
  $exclude = explode(',', $instance['exclude']);
104
-
105
-
106
- #-- if the post has parrents
107
  if($post->ancestors){
108
-
109
- $parent = $wpdb->get_var( "SELECT post_parent from wp_posts WHERE ID=".$post->ID );
110
-
111
- //--- If there is a parent of the post set $p to it and check if there is a parent as well
112
- while($parent != FALSE){
113
- $p = $parent;
114
- $parent = $wpdb->get_var( "SELECT post_parent from wp_posts WHERE ID=".$parent);
115
- }
116
-
117
  } else {
118
  #--------- If this is the parent ------------------------------------------------
119
- $p = $post->ID;
120
  }
121
-
122
- #-- Makes this work with all table prefixes
123
- #-- Added 1/22/12
124
- global $table_prefix;
125
-
126
 
127
- $result = $wpdb->get_results( "SELECT ID FROM ".$table_prefix."posts WHERE post_parent = $p AND post_type='page' Order by menu_order" );
128
-
 
 
 
 
 
 
 
129
  #---- if there are no children do not display the parent unless it is check to do so
130
- if($result != false || ( $instance['include_childless_parent'] == 'checked' && !in_array($p, $exclude) ) ){
131
 
132
  if( $instance['css'] == 'checked' ){
133
  echo '<style type="text/css">';
134
- include( advanced_sidebar_menu_functions::file_hyercy('sidebar-menu.css' ) );
135
-
136
  echo '</style>';
137
-
138
-
139
  }
140
 
141
-
142
- #-- Bring in the output
143
- require( advanced_sidebar_menu_functions::file_hyercy( 'page_list.php' ) );
144
-
145
- }
 
 
146
  }
 
147
  } #== /widget()
148
 
149
  } #== /Clas
5
  * Creates a Widget of parent Child Pages
6
  *
7
  * @author mat lipe
8
+ * @since 7/16/12
9
  * @package Advanced Sidebar Menu
10
  *
11
  */
12
 
13
 
14
+
15
  class advanced_sidebar_menu_page extends WP_Widget {
16
 
17
  #-----------------------------------------------------------------------------------------------------------------------------------
19
  function form( $instance ) {
20
  // require( ADVANCED_SIDEBAR_DIR . 'advanced-sidebar-menu.js' );
21
  ?>
22
+
23
+ <p> Title <br>
24
+ <input id="<?php echo $this->get_field_name('title'); ?>"
25
+ name="<?php echo $this->get_field_name('title'); ?>" size="50" type="text" value="<?php echo $instance['title']; ?>"/></p>
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> Use Built in Styling: <input id="<?php echo $this->get_field_name('css'); ?>"
37
  name="<?php echo $this->get_field_name('css'); ?>" type="checkbox" value="checked"
38
  <?php echo $instance['css']; ?>/></p>
39
 
40
+ <p> Pages to Exclude, Comma Separated: <input id="<?php echo $this->get_field_name('exclude'); ?>"
41
  name="<?php echo $this->get_field_name('exclude'); ?>" type="text" value="<?php echo $instance['exclude']; ?>"/></p>
42
 
43
+ <p> Always Display Child Pages: <input id="<?php echo $this->get_field_name('display_all'); ?>"
44
  name="<?php echo $this->get_field_name('display_all'); ?>" type="checkbox" value="checked"
45
  onclick="javascript:asm_reveal_element( 'levels-<?php echo $this->get_field_name('levels'); ?>' )"
46
  <?php echo $instance['display_all']; ?>/></p>
51
  } else {
52
  echo 'display:none';
53
  } ?>">
54
+ <p> Levels to Display: <select id="<?php echo $this->get_field_name('levels'); ?>"
55
  name="<?php echo $this->get_field_name('levels'); ?>">
56
  <?php
57
  for( $i= 1; $i<6; $i++ ){
75
  $instance['display_all'] = strip_tags($new_instance['display_all']);
76
  $instance['levels'] = strip_tags($new_instance['levels']);
77
  $instance['css'] = strip_tags($new_instance['css']);
78
+ $instance['title'] = strip_tags($new_instance['title']);
79
  return $instance;
80
  }
81
 
85
  function advanced_sidebar_menu_page( ) {
86
  /* Widget settings. */
87
  $widget_ops = array( 'classname' => 'sidebar-menu', 'description' => 'Creates a menu of all the pages using the child/parent relationship' );
88
+ $control_ops = array( 'width' => 290 );
89
 
90
  /* Create the widget. */
91
+ $this->WP_Widget( 'advanced_sidebar_menu', 'Advanced Sidebar Pages Menu', $widget_ops, $control_ops);
92
  }
93
 
94
 
96
 
97
  // adds the output to the widget area on the page
98
  function widget($args, $instance) {
99
+
100
+ if( is_page() ){
101
 
102
+ global $wpdb, $post, $table_prefix, $asm;
 
 
 
 
103
 
104
  #-- Create a usable array of the excluded pages
105
  $exclude = explode(',', $instance['exclude']);
106
+
107
+ #-- if the post has parents
 
108
  if($post->ancestors){
109
+ $top_parent = end( $post->ancestors );
 
 
 
 
 
 
 
 
110
  } else {
111
  #--------- If this is the parent ------------------------------------------------
112
+ $top_parent = $post->ID;
113
  }
 
 
 
 
 
114
 
115
+ /**
116
+ * Must be done this way to prevent doubling up of pages
117
+ */
118
+ $child_pages = $wpdb->get_results( "SELECT ID FROM ".$table_prefix."posts WHERE post_parent = $top_parent AND post_type='page' AND post_status='publish' Order by menu_order" );
119
+
120
+ //for depreciation
121
+ $p = $top_parent;
122
+ $result = $child_pages;
123
+
124
  #---- if there are no children do not display the parent unless it is check to do so
125
+ if( ($child_pages) || (($instance['include_childless_parent'] == 'checked') && (!in_array($top_parent, $exclude)) ) ){
126
 
127
  if( $instance['css'] == 'checked' ){
128
  echo '<style type="text/css">';
129
+ include( advanced_sidebar_menu_functions::file_hyercy('sidebar-menu.css' ) );
 
130
  echo '</style>';
 
 
131
  }
132
 
133
+ //Start the menu
134
+ echo '<div id="'.$args['widget_id'].'" class="advanced-sidebar-menu widget advanced-sidebar-page">
135
+ <div class="widget-wrap">';
136
+ $asm->set_widget_vars( $instance, $top_parent, $exclude );
137
+ #-- Bring in the view
138
+ require( $asm->file_hyercy( 'page_list.php' ) );
139
+ echo '</div></div><!-- end #'.$args['widget_id'].' -->';
140
  }
141
+ }
142
  } #== /widget()
143
 
144
  } #== /Clas