Wordpress自定义帖子类型 - 类别不起作用

I have have added a custom post type called "Blog" by adding the following code to my functions.php theme file:

function create_posttype() {
  register_post_type( 'blog',
    array(
      'labels' => array(
        'name' => __( 'Blog' ),
        'singular_name' => __( 'Blog' )
      ),
      'public' => true,
      'has_archive' => true,
      'rewrite' => array('slug' => 'blog'),
      'taxonomies'  => array( 'category' ),
    )
  );
}
add_action( 'init', 'create_posttype' );

This has works fine, when viewing www.mysite.co.za/blog/, this page shows all of my posts. However, when I view a category page such as www.mysite.co.za/category/blog/tips/ it displays no posts. This despite having (1) next to the category name displayed in the sidebar and having "This entry was posted on 03 August 2018 under Tips" at the bottom of the post.

Here is the category.php template file:

<?php get_header(); ?>

    <div id="wrap">
        <div id="content" class="column">
<hr class="split style-two">

<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
  <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <div class="post-header">
        <h1><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
        <p class="subhead"> Posted by <?php the_author_posts_link(); ?> on <?php the_time( 'd M Y' ); ?> under <?php the_category(', ') ?>
    <!--<div class="date"><?php the_time( 'M j y' ); ?></div>
        <div class="author"><?php the_author(); ?></div>-->
    </div><!--end post header-->
    <div class="entry clear">
<div class="image-frame">   
<a href="<?php the_permalink(); ?>"><?php if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail(); ?></a>
</div>
        <?php the_content('<br><span class="moretext">Read More</span>'); ?>
        <?php wp_link_pages(); ?>
    </div><!--end entry-->
    <div class="post-footer">
        <div class="comments"><?php comments_popup_link( 'Leave a Comment', '1 Comment', '% Comments', 'commentbutton' ); ?></div>
    </div><!--end post footer-->
  </div><!--end post--><br><hr class="split style-two">
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
  <div class="navigation index">
    <div class="alignleft"><?php next_posts_link( 'Older Entries' ); ?></div>
    <div class="alignright"><?php previous_posts_link( 'Newer Entries' ); ?></div>
  </div><!--end navigation-->

<?php else : ?>
<?php endif; ?>

        </div>

        <div id="sidebar" class="column">
            <?php get_sidebar(); ?>
        </div>
    </div>

</div>

<?php get_footer(); ?>

What is causing the category page to not display any posts?

Thanks in advance
Willem

You are now sharing WordPress default Post's categories in your new CPT and 'category.php' in default will show 'Posts' and not your CPT. If you are not going to use WordPress default Posts anymore, you can add the following to your theme's 'functions.php'.

add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
    if((is_category() || is_tag()) && !is_admin()) {
        $query->set('post_type','blog');
        return $query;
    }
}

But I would recommend you to create a custom taxonomy for your CPT using register_taxonomy(). You can read more here - https://www.smashingmagazine.com/2012/01/create-custom-taxonomies-wordpress/.

Try registering your custom post types to main query and see if it works

// Show posts of 'post', 'page' and 'blog' post types
function add_custom_post_types_to_query( $query ) {
    $query->set( 'post_type', array( 'post', 'page', 'blog' ) );
  return $query;
}
add_action( 'pre_get_posts', 'add_custom_post_types_to_query' );

The above code goes in functions.php file