After adding Bangla Tags and Category, I want to display them as the default category and tag with the custom post type. We already know that Bangla tags are categories are worked as custom taxonomy, and that is why we can use a get_taxonomies function to display both. So, the first thing is first, to show custom taxonomy, we need a different template to render our custom post type. As the rule of WordPress, every single post of a custom post type can be easily rendered by a template that needs to create by its slug name.
How to display Bangla Tags and Category:
In our case, we use ‘bangla‘ as the post type name, and we can explore all ‘bangla‘ posts by visiting this simple URI: https://www.varyhelp.com/bangla/. So our custom post type slug name is ‘bangla’ and we can simply use this name to make our custom single template to render this type of posts. So, here is the simple step by step process to display Bangla tags and Category in a custom template.
Create a custom template for the custom post type. You can easily do it by creating a new .php file in your root directory. Now, rename the file as single-bangla.php. If you want to create an archive page for the custom post type, you can rename it as archive-bangla.php. So, WordPress automatically detect these templates for custom post type and render them as well as you coded them.
Copy the codes from single.php file and paste into single-bangla.php. Now, focus on the code. If you see that the “the_content” function called another template, e.g. (content or article), then you can go for further to open the specified template. Otherwise, look for the piece of code, which calls the category or tags. In my case, the code looks like the below in content.php:
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && categorized_blog() ) : ?> <div class="entry-meta"> <span class="cat-links"> <?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', '' ) ); ?> </span> </div>
And, I replace it by the following codes in another template named bangla-content.php and call it instead of content.php in the single-bangla.php template. Here’s the code:
<a class="category-defult-bg category-bg-color-<?php echo $cat_id; ?>" href="<?php echo $cat_link; ?>"><?php echo get_the_term_list( $wp_query->post->ID, 'bangla-category', '', ', ', '' ); ?></a>
I also call the tags in the same way to display them, and they do well without any error. Here’s the code for bangla-tag:
<a class="tag-<?php echo $term_id; ?>" href="<?php echo $term_link; ?>"> <?php echo get_the_term_list( $wp_query->post->ID, 'bangla-tag', '', ', ', '' ); ?></a>
Summary of the task: After all, to render the custom post type first create the template for them and replace the code for tags and categories with your custom terms and taxonomies. Always, backup your files before doing it and avoid the process if you are not an expert in .php. You can simply create a raw file for custom post type and then add the code snippet to display the term list. But the success actually depends on your expertise.