Skip to content

Instantly share code, notes, and snippets.

@jonesch
Created October 11, 2012 14:01
Show Gist options
  • Save jonesch/3872506 to your computer and use it in GitHub Desktop.
Save jonesch/3872506 to your computer and use it in GitHub Desktop.
Custom Sidebar Menu for Children - Wordpress
//Create a custom sidebar piece that displays the pages/menus for us
function create_sidebar_menu_pages($current_id, $parent_id, $children_pages = null){
$output = '';
$output .= '<h3>';
if(empty($children_pages)){
$output .= 'Other Useful Links';
} else {
$output .= '<a href="'.get_permalink($current_id).'">'.get_the_title($parent_id).'</a>';
}
$output .= '</h3>';
$output .= '<nav role="sidebar-navigation">';
$output .= '<ul>';
foreach($children_pages as $page){
$output .= '<li><a href="'.get_permalink($page->ID).'"'.($page->ID==$current_id?' class="active"':'').'>'.$page->post_title.'</a>';
}
$output .= '</ul>';
$output .= '</nav><!-- sidebar-navigation -->';
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment