Version Description
Download this release
Release Info
Developer | Mat Lipe |
Plugin | Advanced Sidebar Menu |
Version | 4.3.1 |
Comparing to | |
See all releases |
Code changes from version 4.2.2 to 4.3.1
- advanced-sidebar-menu.php +2 -2
- lib/advancedSidebarMenu.php +36 -15
- readme.txt +5 -2
- views/category_list.php +43 -47
- widgets/category.widget.php +48 -26
advanced-sidebar-menu.php
CHANGED
@@ -4,9 +4,9 @@ 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: 4.
|
8 |
Author URI: http://lipeimagination.info
|
9 |
-
Since:
|
10 |
*/
|
11 |
|
12 |
|
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: 4.3.1
|
8 |
Author URI: http://lipeimagination.info
|
9 |
+
Since: 6.7.13
|
10 |
*/
|
11 |
|
12 |
|
lib/advancedSidebarMenu.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
/**
|
5 |
* These Functions are Specific to the Advanced Sidebar Menu
|
6 |
* @author Mat Lipe
|
7 |
-
* @since
|
8 |
*
|
9 |
* @package Advanced Sidebar Menu
|
10 |
*/
|
@@ -15,6 +15,8 @@ class advancedSidebarMenu{
|
|
15 |
var $ancestors; //For the category ancestors
|
16 |
var $count = 1; //Count for grandchild levels
|
17 |
var $order_by;
|
|
|
|
|
18 |
|
19 |
|
20 |
|
@@ -33,27 +35,41 @@ class advancedSidebarMenu{
|
|
33 |
return false;
|
34 |
|
35 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
/**
|
38 |
* Retrieves the Highest level Category Id
|
39 |
*
|
40 |
-
* @since
|
41 |
* @param int $catId - id of cat looking for top parent of
|
42 |
*
|
43 |
* @return int
|
44 |
*/
|
45 |
function getTopCat( $catId ){
|
46 |
$cat_ancestors = array();
|
47 |
-
$cat_ancestors[] = $catId
|
48 |
-
|
49 |
-
|
50 |
-
$
|
51 |
-
$
|
52 |
-
$cat_ancestors[] = $
|
53 |
}
|
54 |
-
while ($
|
55 |
-
|
56 |
-
|
57 |
//Reverse the array to start at the last
|
58 |
$this->ancestors = array_reverse( $cat_ancestors );
|
59 |
|
@@ -64,6 +80,7 @@ class advancedSidebarMenu{
|
|
64 |
|
65 |
|
66 |
|
|
|
67 |
/**
|
68 |
* Removes the closing </li> tag from a list item to allow for child menus inside of it
|
69 |
*
|
@@ -185,11 +202,15 @@ class advancedSidebarMenu{
|
|
185 |
*
|
186 |
* IF this is a top level category
|
187 |
* @param obj $cat the cat object
|
|
|
|
|
188 |
*/
|
189 |
function first_level_category( $cat ){
|
190 |
-
|
|
|
191 |
return true;
|
192 |
} else {
|
|
|
193 |
return false;
|
194 |
}
|
195 |
}
|
@@ -197,13 +218,13 @@ class advancedSidebarMenu{
|
|
197 |
/**
|
198 |
* If the cat is a second level cat
|
199 |
* @param obj $cat the cat
|
200 |
-
* @since
|
201 |
*/
|
202 |
function second_level_cat( $child_cat ){
|
203 |
//if this is the currrent cat or a parent of the current cat
|
204 |
-
if( $child_cat->
|
205 |
$all_children = array();
|
206 |
-
$all_children =
|
207 |
if( !empty( $all_children ) ){
|
208 |
return true;
|
209 |
} else {
|
4 |
/**
|
5 |
* These Functions are Specific to the Advanced Sidebar Menu
|
6 |
* @author Mat Lipe
|
7 |
+
* @since 6.6.13
|
8 |
*
|
9 |
* @package Advanced Sidebar Menu
|
10 |
*/
|
15 |
var $ancestors; //For the category ancestors
|
16 |
var $count = 1; //Count for grandchild levels
|
17 |
var $order_by;
|
18 |
+
var $taxonomy; //For filters to override the taxonomy
|
19 |
+
var $current_term; //Current category or taxonomy
|
20 |
|
21 |
|
22 |
|
35 |
return false;
|
36 |
|
37 |
}
|
38 |
+
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Used by a uasort to sort taxonomy arrays by term order
|
42 |
+
*
|
43 |
+
* @since 4.3.0
|
44 |
+
*/
|
45 |
+
function sortTerms( $a, $b ){
|
46 |
+
if( !isset($a->{$this->order_by}) || !isset($b->{$this->order_by}) ) return 0;
|
47 |
+
|
48 |
+
return $a->{$this->order_by} > $b->{$this->order_by};
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
|
53 |
|
54 |
/**
|
55 |
* Retrieves the Highest level Category Id
|
56 |
*
|
57 |
+
* @since 6.6.13
|
58 |
* @param int $catId - id of cat looking for top parent of
|
59 |
*
|
60 |
* @return int
|
61 |
*/
|
62 |
function getTopCat( $catId ){
|
63 |
$cat_ancestors = array();
|
64 |
+
$cat_ancestors[] = $catId;
|
65 |
+
|
66 |
+
do {
|
67 |
+
$catId = get_term($catId, $this->taxonomy);
|
68 |
+
$catId = $catId->parent;
|
69 |
+
$cat_ancestors[] = $catId;
|
70 |
}
|
71 |
+
while ($catId);
|
72 |
+
|
|
|
73 |
//Reverse the array to start at the last
|
74 |
$this->ancestors = array_reverse( $cat_ancestors );
|
75 |
|
80 |
|
81 |
|
82 |
|
83 |
+
|
84 |
/**
|
85 |
* Removes the closing </li> tag from a list item to allow for child menus inside of it
|
86 |
*
|
202 |
*
|
203 |
* IF this is a top level category
|
204 |
* @param obj $cat the cat object
|
205 |
+
*
|
206 |
+
* @since 6.7.13
|
207 |
*/
|
208 |
function first_level_category( $cat ){
|
209 |
+
|
210 |
+
if( !in_array($cat->term_id, $this->exclude) && $cat->parent == $this->top_id){
|
211 |
return true;
|
212 |
} else {
|
213 |
+
|
214 |
return false;
|
215 |
}
|
216 |
}
|
218 |
/**
|
219 |
* If the cat is a second level cat
|
220 |
* @param obj $cat the cat
|
221 |
+
* @since 6.7.13
|
222 |
*/
|
223 |
function second_level_cat( $child_cat ){
|
224 |
//if this is the currrent cat or a parent of the current cat
|
225 |
+
if( $child_cat->term_id == $this->current_term || in_array( $child_cat->term_id, $this->ancestors )){
|
226 |
$all_children = array();
|
227 |
+
$all_children = get_terms( $this->taxonomy, array( 'child_of' => $child_cat->term_id ) );
|
228 |
if( !empty( $all_children ) ){
|
229 |
return true;
|
230 |
} else {
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypa
|
|
4 |
Tags: menus, sidebar menu, heirchy, category menu, pages menu
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 3.5.1
|
7 |
-
Stable tag: 4.
|
8 |
|
9 |
Creates a widget for both page and categories that will display the current page/category and all child pages or categories.
|
10 |
|
@@ -19,7 +19,8 @@ Includes Page options:
|
|
19 |
<li>Add a title to the widget</li>
|
20 |
<li>Include the highest level parent page</li>
|
21 |
<li>Include the highest level parent page even with no Children</li>
|
22 |
-
|
|
|
23 |
<li>Exclude pages</li>
|
24 |
<li>Legacy Mode - For those who like the way it was pre version 4.0</li>
|
25 |
<li>Always display child Pages</li>
|
@@ -112,6 +113,8 @@ I do offer preminum services for buiding custom add-ons for additional functiona
|
|
112 |
|
113 |
|
114 |
== Changelog ==
|
|
|
|
|
115 |
|
116 |
= 4.2.0 =
|
117 |
* Added Order By Selection in Page Widget
|
4 |
Tags: menus, sidebar menu, heirchy, category menu, pages menu
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 3.5.1
|
7 |
+
Stable tag: 4.3.1
|
8 |
|
9 |
Creates a widget for both page and categories that will display the current page/category and all child pages or categories.
|
10 |
|
19 |
<li>Add a title to the widget</li>
|
20 |
<li>Include the highest level parent page</li>
|
21 |
<li>Include the highest level parent page even with no Children</li>
|
22 |
+
<li>Order Pages By (date, title, page order)</li>
|
23 |
+
<li>Use built in styling (very plain styling currently but plans for more advanced in near future versions)</li>
|
24 |
<li>Exclude pages</li>
|
25 |
<li>Legacy Mode - For those who like the way it was pre version 4.0</li>
|
26 |
<li>Always display child Pages</li>
|
113 |
|
114 |
|
115 |
== Changelog ==
|
116 |
+
= 4.3.0 =
|
117 |
+
* Added many filters into the category widget for things like taxonomies, parent category, display on override, order by, and much more. There is no UI support for any of this yet, but developers may now tap into this.
|
118 |
|
119 |
= 4.2.0 =
|
120 |
* Added Order By Selection in Page Widget
|
views/category_list.php
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
-
* The Ouput of
|
5 |
* @author Mat Lipe
|
6 |
-
* @since 4.1
|
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
|
@@ -11,64 +11,60 @@
|
|
11 |
* @param Do not edit this file in this location or it will break on update
|
12 |
*/
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
$content = '';
|
18 |
|
19 |
//Include the parent page if chosen
|
20 |
if( $asm->include_parent() ){
|
21 |
-
|
22 |
-
|
23 |
|
24 |
}
|
25 |
|
26 |
-
|
27 |
//If there are children to display
|
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 |
$content .= '</li>';
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
+
* The Ouput of the Advanced Sidebar Categories Widget
|
5 |
* @author Mat Lipe
|
6 |
+
* @since 4.3.1
|
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
|
11 |
* @param Do not edit this file in this location or it will break on update
|
12 |
*/
|
13 |
|
|
|
|
|
|
|
14 |
$content = '';
|
15 |
|
16 |
//Include the parent page if chosen
|
17 |
if( $asm->include_parent() ){
|
18 |
+
$content .= '<ul class="parent-sidebar-menu">';
|
19 |
+
$content .= $asm->openListItem( wp_list_categories( 'echo=0&orderby='.$asm->order_by.'&taxonomy='.$asm->taxonomy.'&title_li=&hide_empty=0&include=' . trim($asm->top_id)) );
|
20 |
|
21 |
}
|
22 |
|
|
|
23 |
//If there are children to display
|
24 |
+
if( !empty($all_categories) ){
|
25 |
+
$content .= '<ul class="child-sidebar-menu">';
|
26 |
|
27 |
+
#-- If they want all the child categories displayed always
|
28 |
+
if( $asm->display_all() ){
|
29 |
+
$content .= wp_list_categories('echo=0&orderby='.$asm->order_by.'&taxonomy='.$asm->taxonomy.'&title_li=&child_of=' . $asm->top_id .'&depth=' .$instance['levels'] );
|
30 |
|
31 |
+
} else {
|
32 |
|
33 |
+
#-- to Display the categories based a parent child relationship
|
34 |
+
foreach( $all_categories as $child_cat ){
|
35 |
+
|
36 |
+
//IF this is a child category of the top one
|
37 |
+
if( $asm->first_level_category( $child_cat ) ){
|
38 |
+
|
39 |
+
//List the child category and the children if it is the current one
|
40 |
+
$content .= $asm->openListItem(wp_list_categories('echo=0&orderby='.$asm->order_by.'&taxonomy='.$asm->taxonomy.'&title_li=&include=' . $child_cat->term_id . '&depth=1' ) );
|
41 |
|
42 |
+
|
43 |
+
//If there are children of this cat and it is a parent or child or the current cat
|
44 |
+
if( $asm->second_level_cat( $child_cat ) ){
|
45 |
+
#-- Create a new menu with all the children under it
|
46 |
+
$content .= '<ul class="grandchild-sidebar-menu">';
|
47 |
+
$content .= wp_list_categories('echo=0&orderby='.$asm->order_by.'&taxonomy='.$asm->taxonomy.'&title_li=&exclude='.$instance['exclude'].'&depth=3&child_of=' .$child_cat->term_id );
|
48 |
+
$content .= '</ul>';
|
49 |
+
|
50 |
+
}
|
51 |
|
52 |
$content .= '</li>';
|
53 |
+
}
|
54 |
+
} //End foreach
|
55 |
+
|
56 |
+
|
57 |
|
58 |
+
} //End if display all is not checked
|
59 |
+
|
60 |
+
$content .= '</ul><!-- End #child-sidebar-menu -->';
|
61 |
+
|
62 |
+
} //End if the are child categories
|
63 |
+
|
64 |
+
|
65 |
+
#-- if a parent category was displayed
|
66 |
+
if( $asm->include_parent() ){
|
67 |
+
$content .= '</li>
|
68 |
+
</ul><!-- End #parent-sidebar-menu -->';
|
69 |
+
}
|
70 |
|
widgets/category.widget.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* Creates a Widget of parent Child Categories
|
6 |
*
|
7 |
* @author mat lipe
|
8 |
-
* @since
|
9 |
* @package Advanced Sidebar Menu
|
10 |
*
|
11 |
*/
|
@@ -138,10 +138,13 @@ class advanced_sidebar_menu_category extends WP_Widget {
|
|
138 |
/**
|
139 |
* Outputs the categories widget to the page
|
140 |
*
|
141 |
-
* @since
|
142 |
* @uses loads the views/category_list.php
|
143 |
*
|
144 |
-
* @filters apply_filters('advanced_sidebar_menu_category_widget_output', $content, $args, $instance );
|
|
|
|
|
|
|
145 |
*
|
146 |
*/
|
147 |
function widget($args, $instance) {
|
@@ -154,26 +157,42 @@ class advanced_sidebar_menu_category extends WP_Widget {
|
|
154 |
$legacy = $asm->checked('legacy_mode');
|
155 |
|
156 |
$cat_ids = $already_top = array();
|
157 |
-
$asm_once =
|
158 |
-
|
159 |
|
160 |
$exclude = explode(',', $instance['exclude']);
|
161 |
$asm->exclude = $exclude;
|
162 |
|
|
|
|
|
163 |
extract( $args);
|
164 |
|
165 |
-
|
166 |
//If on a single page create an array of each category and create a list for each
|
167 |
-
if( is_single()
|
168 |
-
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
$cat_ids[] = $cat->term_id;
|
171 |
}
|
172 |
|
173 |
//IF on a category page get the id of the category
|
174 |
-
} elseif( is_category() ){
|
175 |
-
$
|
|
|
176 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
|
178 |
//Go through each category there will be only one if this is a category page mulitple possible if this is single
|
179 |
foreach( $cat_ids as $cat_id ){
|
@@ -187,7 +206,16 @@ class advanced_sidebar_menu_category extends WP_Widget {
|
|
187 |
$already_top[] = $asm->top_id;
|
188 |
|
189 |
//Check for children
|
190 |
-
$all_categories = $all = array_filter(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
|
193 |
//If there are no children and not displaying childless parent - bail
|
@@ -209,30 +237,24 @@ class advanced_sidebar_menu_category extends WP_Widget {
|
|
209 |
include( $asm->file_hyercy('sidebar-menu.css', $legacy ) );
|
210 |
echo '</style>';
|
211 |
}
|
212 |
-
|
213 |
-
$count++; // To change the id of the widget if there are multiple
|
214 |
$asm_once = true; //There has been a div
|
215 |
$close = true; //The div should be closed at the end
|
216 |
|
217 |
if($instance['new_widget'] == 'list'){
|
218 |
$close = false; //If this is a list leave it open for now
|
219 |
}
|
220 |
-
|
221 |
-
} else {
|
222 |
-
$close = false;
|
223 |
-
}
|
224 |
-
|
225 |
-
|
226 |
-
//for deprecation
|
227 |
-
$top_cat = $cat_id;
|
228 |
-
$cat_ancestors = $asm->ancestors;
|
229 |
-
|
230 |
}
|
|
|
|
|
|
|
|
|
|
|
231 |
|
232 |
//Bring in the view
|
233 |
require( $asm->file_hyercy( 'category_list.php', $legacy ) );
|
234 |
-
|
235 |
-
|
236 |
echo apply_filters('advanced_sidebar_menu_category_widget_output', $content, $args, $instance );
|
237 |
|
238 |
if( $close ){
|
5 |
* Creates a Widget of parent Child Categories
|
6 |
*
|
7 |
* @author mat lipe
|
8 |
+
* @since 6.7.13
|
9 |
* @package Advanced Sidebar Menu
|
10 |
*
|
11 |
*/
|
138 |
/**
|
139 |
* Outputs the categories widget to the page
|
140 |
*
|
141 |
+
* @since 6.7.13
|
142 |
* @uses loads the views/category_list.php
|
143 |
*
|
144 |
+
* @filters apply_filters('advanced_sidebar_menu_category_widget_output', $content, $args, $instance );
|
145 |
+
* apply_filters('advanced_sidebar_menu_taxonomy', 'post', $args, $instance );
|
146 |
+
* apply_filters('advanced_sidebar_menu_proper_single', $asm->checked('single'), $args, $instance)
|
147 |
+
* apply_filters( 'advanced_sidebar_menu_category_ids', $cat_ids, $args, $instance )
|
148 |
*
|
149 |
*/
|
150 |
function widget($args, $instance) {
|
157 |
$legacy = $asm->checked('legacy_mode');
|
158 |
|
159 |
$cat_ids = $already_top = array();
|
160 |
+
$asm_once = false; //keeps track of how many widgets this created
|
161 |
+
|
162 |
|
163 |
$exclude = explode(',', $instance['exclude']);
|
164 |
$asm->exclude = $exclude;
|
165 |
|
166 |
+
$asm->taxonomy = apply_filters('advanced_sidebar_menu_taxonomy', 'category', $args, $instance );
|
167 |
+
|
168 |
extract( $args);
|
169 |
|
|
|
170 |
//If on a single page create an array of each category and create a list for each
|
171 |
+
if( is_single() ){
|
172 |
+
if( !apply_filters('advanced_sidebar_menu_proper_single', $asm->checked('single'), $args, $instance) ) return;
|
173 |
+
global $post;
|
174 |
+
$category_array = wp_get_object_terms($post->ID, $asm->taxonomy);
|
175 |
+
|
176 |
+
//Sort by term_order to work with some plugins
|
177 |
+
$asm->order_by = apply_filters('advanced_sidebar_menu_category_orderby', 'name', $args, $instance );
|
178 |
+
|
179 |
+
uasort( $category_array, array( $asm, 'sortTerms'));
|
180 |
+
|
181 |
+
foreach( $category_array as $id => $cat ){
|
182 |
$cat_ids[] = $cat->term_id;
|
183 |
}
|
184 |
|
185 |
//IF on a category page get the id of the category
|
186 |
+
} elseif( is_tax() || is_category() ){
|
187 |
+
$asm->current_term = get_queried_object()->term_id;
|
188 |
+
$cat_ids[] = get_queried_object()->term_id;
|
189 |
}
|
190 |
+
|
191 |
+
|
192 |
+
|
193 |
+
$cat_ids = apply_filters( 'advanced_sidebar_menu_category_ids', $cat_ids, $args, $instance );
|
194 |
+
|
195 |
+
if( empty( $cat_ids ) ) return;
|
196 |
|
197 |
//Go through each category there will be only one if this is a category page mulitple possible if this is single
|
198 |
foreach( $cat_ids as $cat_id ){
|
206 |
$already_top[] = $asm->top_id;
|
207 |
|
208 |
//Check for children
|
209 |
+
$all_categories = $all = array_filter( get_terms( $asm->taxonomy, array(
|
210 |
+
'child_of' => $child_cat->cat_ID,
|
211 |
+
'orderby' => $asm->order_by )
|
212 |
+
)
|
213 |
+
);
|
214 |
+
//For Backwards Compatibility
|
215 |
+
foreach( $all_categories as $tc ){
|
216 |
+
$tc->cat_ID = $tc->term_id;
|
217 |
+
}
|
218 |
+
|
219 |
|
220 |
|
221 |
//If there are no children and not displaying childless parent - bail
|
237 |
include( $asm->file_hyercy('sidebar-menu.css', $legacy ) );
|
238 |
echo '</style>';
|
239 |
}
|
240 |
+
|
|
|
241 |
$asm_once = true; //There has been a div
|
242 |
$close = true; //The div should be closed at the end
|
243 |
|
244 |
if($instance['new_widget'] == 'list'){
|
245 |
$close = false; //If this is a list leave it open for now
|
246 |
}
|
247 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
}
|
249 |
+
|
250 |
+
//for deprecation
|
251 |
+
$top_cat = $asm->top_id;
|
252 |
+
$cat_ancestors = $asm->ancestors;
|
253 |
+
|
254 |
|
255 |
//Bring in the view
|
256 |
require( $asm->file_hyercy( 'category_list.php', $legacy ) );
|
257 |
+
|
|
|
258 |
echo apply_filters('advanced_sidebar_menu_category_widget_output', $content, $args, $instance );
|
259 |
|
260 |
if( $close ){
|