This is a quick and dirty plugin for adding a submenu to WordPress, oddly, something I always struggle with, It’s based on WordPress codex code. It creates a widget that can be combined with @wpmudev custom-sidebars plugin, for example. It’s pretty rough and ready, so use at your own risk, you’ll need to create the widget etc, consult the codex.
/**
*
*
* Adds Three_Sub_Menu widget.
*
*
*/
class Three_Sub_Menu extends WP_Widget {
function __construct() {
parent::__construct(
'Three_Sub_Menu', // Base ID
__('TWD: Sub Menu', 'text_domain'), // Name
array( 'description' => __( 'Sub Menu widget', 'twd' ), )
);
}
public function widget( $args, $instance ) {
$queried_object = get_queried_object();
if ( $queried_object ) {
$post_id = $queried_object->ID;
$post_parent = $queried_object->post_parent;
if($post_parent) {
$children = wp_list_pages('title_li=&child_of='.$post_parent.'&echo=0');
$titlenamer = get_the_title($post_parent);
}
else {
$children = wp_list_pages('title_li=&child_of='.$post_id.'&echo=0');
$titlenamer = get_the_title($post_id);
}
}
echo $args['before_widget'];
echo __( '<h2>' . $titlenamer . '</h2><div class="widget-inner"><ul>' . $children . '</ul></div>', 'twd' );
echo $args['after_widget'];
}
}