首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义Post类型存档页显示为404

自定义Post类型存档页显示为404
EN

WordPress Development用户
提问于 2021-02-08 18:11:56
回答 1查看 224关注 0票数 0

因此,我使用CPT插件创建了一个名为Works的自定义post类型。我设置的弹段代码是proctor-work,我创建了一个名为Archi-Proctor-work.php的模板。我不能让它在http://proctordevelop.wpengine.com/proctor-work上显示,它只是不断地显示404页。我的眼镜蛇红了。存档页面中引用的所有文件都已添加到子主题中的站点中。

我还向functions.php添加了一个注册。(见下文)有人能帮忙吗?

以下是存档页面的代码:

代码语言:javascript
复制
<?php
    /**
     * The template for displaying Our Work
     *
     * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
     *
     */
    
    get_header();
    ?>
    
        <section id="primary" class="content-area post-listing -listing">
            <main id="main" class="site-main">
    
            <?php if ( have_posts() ) : ?>
                
    
                <?php include 'our-work-filters.php'; ?>
    
                <div class="center container">
                <?php
                /* Start the Loop */
                while ( have_posts() ) :
                    the_post();
    
                    /*
                     * Include the Post-Type-specific template for the content.
                     * If you want to override this in a child theme, then include a file
                     * called content-___.php (where ___ is the Post Type name) and that will be used instead.
                     */
                    get_template_part( 'proctor_content', get_post_type() );
    
                endwhile;
            ?>
                <!-- <div class="pagination"><?php wpex_pagination(); ?></div> -->
            <?php
            else :
    
                get_template_part( 'proctor_content', 'none' );
    
            endif;
            ?>
        </div>
            </main><!-- #main -->
        </div><!-- #primary -->
    
    <?php
    get_footer();

登记码

代码语言:javascript
复制
function wporg_custom_post_type() {
    register_post_type('proctor-work',
        array(
            'labels'      => array(
                'name'          => __( 'Works', 'textdomain' ),
                'singular_name' => __( 'Work', 'textdomain' ),
            ),
            'public'      => true,
            'has_archive' => true,
            'rewrite'     => array( 'slug' => 'proctor-work' ), // my custom slug
        )
    );
}  
EN

回答 1

WordPress Development用户

发布于 2021-02-09 05:01:54

注册custom_post_type时,也要使用这些参数。

'publicly_queryable‘=>真,

那它应该是这样的。

代码语言:javascript
复制
function wporg_custom_post_type() {
register_post_type('proctor-work',
    array(
        'labels'      => array(
            'name'          => __( 'Works', 'textdomain' ),
            'singular_name' => __( 'Work', 'textdomain' ),
        ),
        'public'      => true,
        'has_archive' => true,
        'rewrite'     => array( 'slug' => 'proctor-work' ), // my custom slug
        'publicly_queryable'    => true
    )
);

}

票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/383035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档