How do i display all categories of a custom post type and have respective page for them?

I made a custom Post type named Blogs which is like this on the function.php

function blog_post() {
$labels = array(
‘name’ => _x( ‘Blogs’, ‘post type general name’ ),
‘singular_name’ => _x( ‘Blog’, ‘post type singular name’ ),
‘add_new’ => _x( ‘Add New Blog’, ‘blog’ ),
‘add_new_item’ => __( ‘Add New Blogs’ ),
‘edit_item’ => __( ‘Edit Blog’ ),
‘new_item’ => __( ‘New Blog’ ),
‘all_items’ => __( ‘All Blogs’ ),
‘view_item’ => __( ‘View Blog’ ),
‘search_items’ => __( ‘Search Blogs’ ),
‘not_found’ => __( ‘No blog found’ ),
‘not_found_in_trash’ => __( ‘No blog found in the Trash’ ),
‘parent_item_colon’ => ”,
‘menu_name’ => ‘Blogs’
);
$args = array(
‘labels’ => $labels,
‘description’ => ‘Holds blogs and blog specific data’,
‘public’ => true,
‘menu_position’ => 5,
‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’, ‘excerpt’, ‘comments’ ),
‘has_archive’ => true,
);
register_post_type( ‘blogs’, $args );
}
add_action( ‘init’, ‘blog_post’ );

function blog_categories() {
$labels = array(
‘name’ => _x( ‘Blog Categories’, ‘taxonomy general name’ ),
‘singular_name’ => _x( ‘Blog Category’, ‘taxonomy singular name’ ),
‘search_items’ => __( ‘Search Blog Categories’ ),
‘all_items’ => __( ‘All Blogs Categories’ ),
‘parent_item’ => __( ‘Parent Blog Category’ ),
‘parent_item_colon’ => __( ‘Parent Blog Category:’ ),
‘edit_item’ => __( ‘Edit Blog Category’ ),
‘update_item’ => __( ‘Update Blog Category’ ),
‘add_new_item’ => __( ‘Add New Blog Category’ ),
‘new_item_name’ => __( ‘New Blog Category’ ),
‘menu_name’ => __( ‘Blog Categories’ ),
);
$args = array(
‘labels’ => $labels,
‘hierarchical’ => true,
);
register_taxonomy( ‘blogs’, ‘blogs’, $args );
}
add_action( ‘init’, ‘blog_categories’, 0 );

So i made the Custom Post type like this

Now i created Post on the Blogs with Categories as Everything, Who, Where now i want to have a page which displays all categories and when i click respective category name i want to have a page which shows pages as per the categories
So i wrote a code on blog.php

<?php
$args = array(
‘taxonomy’ => ‘blogs’,
‘orderby’ => ‘name’,
‘order’ => ‘ASC’
);

$categoriess = get_categories($args);

foreach($categoriess as $cat) {
?>
<a href=”<?php echo get_category_link( $cat->term_id ) ?>”>
<?php echo $cat->name; ?>
</a>

So this code just shows Blog categories but i am super confused which page should i write the code for each categories and stuff please help me?

Read more here:: How do i display all categories of a custom post type and have respective page for them?

Leave a Reply

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