Skip to content
Jared Atchison edited this page Apr 17, 2015 · 4 revisions

Helpful Snippets

Always show children and grandchildren under parent

/**
 * Customize the BE Subpages widget to always show the children and grandchildren
 *
 * @param array $parents
 * @return array
 */
function be_subpages_widget_parents_args( $parents ) {
	$pages =  get_pages( array( 'child_of' => $parents[0] ) );
	foreach ( $pages as $page ) {
		$parents[] = $page->ID;
	} 

	return $parents;
}
add_filter( 'be_subpages_widget_parents', 'be_subpages_widget_parents_args' );

On grandchildren, use active class on top parent items

/**
 * Mark top level as current.
 *
 * @since 1.0.0
 */
function ja_be_subpages_toplevel( $class, $subpage ) {
	global $post;
	if ( $subpage->ID == $post->post_parent ) {
		$class[] .= 'widget_subpages_current_page';
	}
	return $class;	
}
add_filter( 'be_subpages_widget_class', 'ja_be_subpages_toplevel', 10, 2 );
Clone this wiki locally