Last active
August 29, 2015 14:18
-
-
Save iamcanadian1973/500971315584f008a335 to your computer and use it in GitHub Desktop.
Add current parent class to Bill Erickson's Sub Page Widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Add current parent class to Bill Erickson's Sub Page Widget | |
add_filter('be_subpages_widget_class', 'be_add_class', 10, 2); | |
function be_add_class( $class, $subpage ) { | |
global $post; | |
$class[] = 'menu-' . sanitize_title( $subpage->post_title ); | |
if ( $subpage->ID == $post->ID ) | |
$class[] = 'current-menu-item'; | |
if( get_current_page_depth( $post->ID ) > 1 && $subpage->ID == $post->post_parent ) | |
$class[] = 'current-menu-ancestor'; | |
return $class; | |
} | |
/** | |
* Get current page depth | |
* | |
* @return integer | |
*/ | |
function get_current_page_depth( $page_id = '' ){ | |
global $wp_query; | |
$object = $wp_query->get_queried_object(); | |
$parent_id = $object->post_parent; | |
$depth = 0; | |
while($parent_id > 0){ | |
$page = get_page($parent_id); | |
$parent_id = $page->post_parent; | |
$depth++; | |
} | |
return $depth; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment