Register custom post & custom taxonomy in wordpress

Register custom post type

add_action( 'init', 'my_theme_custom_post' );
function my_theme_custom_post() {
	register_post_type( 'cpt',
		array(
			'labels' => array(
				'name' => __( 'CPTs' ),
				'singular_name' => __( 'CPT' )
			),
			'supports' => array('title', 'editor', 'custom-fields', 'thumbnail', 'page-attributes'),
			'public' => true
		)
	);
}

Register custom taxonomy

function my_theme_custom_post_taxonomy() {
	register_taxonomy(
		'cpt_cat',  
		'cpt',                  
		array(
			'hierarchical'          => true,
			'label'                 => 'CPT Category',  
			'query_var'             => true,
			'show_admin_column'     => true,
			'rewrite'               => array(
				'slug'              => 'cpt-category', 
				'with_front'    => true 
				)
			)
	);
}
add_action( 'init', 'my_theme_custom_post_taxonomy');

Register widget in wordpress

function my_custom_theme_widgets() {
	register_sidebar( array(
		'name' => 'My Widget',
		'id' => 'widget_id',
		'before_widget' => '<div class="widget_div">',
		'after_widget' => '</div>',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	) );
}
add_action('widgets_init', 'my_custom_theme_widgets');

You can call widget via below:

Single widget:

<?php dynamic_sidebar('widget_id'); ?>

Conditional

<?php if ( ! dynamic_sidebar( 'sidebar-top' ) ) : ?>
// Your conditional codes
<?php endif; ?>