Custom post not showing

时间:2016-07-29 作者:user agent

我在函数中创建了自定义帖子类型。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();

1 个回复
SO网友:Aftab

请更新您的。htaccess文件。

一旦您能够更新它,您的问题就会得到解决。

当前您的。htaccess文件没有“公文包”slug,所以您需要更新它。

希望这对Hanks有帮助

相关推荐