How to display a separate widget for cpt, in separate sidebar of cpt?

Date: February 21st, 2020
Category: Questions, 264 Views

Asked by: Ela, Location: Johnsburg, McHenry County, Illinois

Hi Manish.

I want to create widgets- ‘archive, tags’ for my ‘portfolio cpt’ and want to display them on my custom sidebar. I have created a separate sidebar for that.

I searched for tutorials, but I am confused with bunch of codes.

My Codes
							
//add custom menus function codex_custom_init() { register_post_type( 'Portfolio', array( 'labels' => array('name' => __( 'Portfolio' ), 'singular_name' => __( 'Portfolio' ) ), 'public' => true, 'has_archive' => true, 'supports' => array('title', 'editor', 'thumbnail', 'comments'), 'menu_icon' => 'dashicons-sos', ) ); //register taxonomy for portfolio post tags register_taxonomy( 'portfolio-tag', //taxonomy 'portfolio', //post-type array( 'hierarchical' => false, 'label' => __( 'Portfolio Tags','taxonomy general name'), 'singular_name' => __( 'Tag', 'taxonomy general name' ), 'rewrite' => true, 'query_var' => true ) ); // add categories for Portfolio register_taxonomy( 'portfoliocategories', 'portfolio', array( 'labels' => array( 'name' => 'Portfolio Categories', 'add_new_item' => 'Add New Portfolio Category', 'new_item_name' => "New Portfolio Type" ), 'show_ui' => true, 'show_tagcloud' => false, 'hierarchical' => true ) ); } add_action( 'init', 'codex_custom_init' ); //enable comments for portfolio function default_comments_on( $data ) { if( $data['post_type'] == 'portfolio' ) { $data['comment_status'] = 'open'; } return $data; } add_filter( 'wp_insert_post_data', 'default_comments_on' );

Answer

Hello Ela, Good day!

Your codes are 100% correct. I will definitely help you out with  ‘custom archives and custom tags’. paste the codes given below inside the div of your custom sidebar.

							
// you can display tags as <?php wp_tag_cloud( array( 'smallest' => 1, // size of least used tag 'largest' => 1, // size of most used tag 'unit' => 'em', // unit for sizing the tags 'number' => 45, // displays at most 45 tags 'orderby' => 'name', // order tags alphabetically 'order' => 'ASC', // order tags by ascending order 'taxonomy' => 'portfolio-tag' // you can even make tags for custom taxonomies ) ); ?> //you can display archives as <?php $args = array( 'type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'echo' => 1, 'order' => 'DESC', 'post_type' => 'portfolio', ); wp_get_archives( $args ); ?>
Share my post: 

Leave a Reply

Your email address will not be published. Required fields are marked *