我在functions.php中注册了一个自定义帖子类型,如下所示:
function wpt_portfolio_posttype() {
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __( 'Portfolio' ),
'singular_name' => __( 'Portfolio Posts' ),
'add_new' => __( 'Add New Portfolio Post' ),
'add_new_item' => __( 'Add New Portfolio Post' ),
'edit_item' => __( 'Edit Portfolio Post' ),
'new_item' => __( 'Add New Portfolio Post' ),
'view_item' => __( 'View Portfolio Post' ),
'search_items' => __( 'Search Portfolio Post' ),
'not_found' => __( 'No Portfolio post found' ),
'not_found_in_trash' => __( 'No Portfolio post found in trash' )
),
'public' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
'capability_type' => 'post',
'rewrite' => array("slug" => "portfolio"), // Permalinks format
'menu_position' => 4,
'menu_icon' => 'dashicons-portfolio',
'taxonomies' => array( 'category' ),
'has_archive' => true,
)
);
}
add_action( 'init', 'wpt_portfolio_posttype' );
它的效果非常好。我可以添加新的投资组合帖子等。但这是我的问题:当我创建一个投资组合帖子时,将它们添加到一个类别(让我们说"个人")并添加一个新的菜单项来显示所有"个人"帖子菜单 - >类别 - >个人菜单,我的自定义帖子类型的所有帖子都不会显示。有谁知道为什么?
这是我的category.php
<?php
get_header(); ?>
<div class="col-sm-9 col-lg-10">
<?php
// Check if there are any posts to display
if ( have_posts() ) : ?>
<div id="content" class="row">
<h1 class="archive-title">Category: <?php single_cat_title( '', false ); ?></h1>
<?php
// Display optional category description
if ( category_description() ) : ?>
<div class="archive-meta"><?php echo category_description(); ?></div>
<?php endif; ?>
<?php
// The Loop
while ( have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<div class="entry">
<?php the_content(); ?>
</div>
<?php endwhile;
else: ?>
<p>Sorry, no posts matched your criteria.</p>
</div>
<?php endif; ?>
</div>
<?php get_footer(); ?>
我还尝试注册自定义类别(并将其还原)但我没有运气从我的自定义帖子类型中获取帖子。有人可以帮助我吗?
提前谢谢!