我在函数中创建了自定义帖子类型。php,代码如下:
function awesome_custom_post_type(){
$labels = array(
\'name\' => \'Portfolio\',
\'singular_name\' => \'Portfolio\',
\'add_new\' => \'Add Item\',
\'all_items\' => \'All Items\',
\'add_new_item\' => \'Add Item\',
\'edit_item\' => \'Edit Item\',
\'new_item\' => \'New Item\',
\'view_item\' => \'View Item\',
\'seach_item\' => \'Search Portfolio\',
\'not_found\' => \'No items found\',
\'not_found_in_trash\' => \'No items found in trash\',
\'parent_item_colon\' => \'Parent Item\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'has_archive\' => true,
\'publicity_queryable\' => true,
\'query_var\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'supports\' => array(
\'title\',
\'editor\',
\'excerpt\',
\'thumbnail\',
\'revisions\',
),
\'taxonomies\' => array(\'category\', \'post_tag\'),
\'menu_position\' => 5,
\'exclude_from_search\' => false
);
register_post_type(\'portfolio\',$args);
}
add_action(\'init\',\'awesome_custom_post_type\');
该公文包添加到我的仪表板上,我可以创建一篇帖子。我看到的问题是,当我在帖子中点击永久链接时,它会给我一个404错误,这样我就可以查看帖子了。
如何查看帖子?
我尝试添加另一个名为single portfolio的文件,但仍然没有成功:
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
get_template_part( \'template-parts/content\', get_post_format() );
the_post_navigation();
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();