因此,我使用CPT插件创建了一个名为Works的自定义帖子类型。我设置的slug是proctor work,我创建了一个名为archive proctor work的模板。php。我不能把这个展示出来http://proctordevelop.wpengine.com/proctor-work, 它只是一直显示404页。我冲洗过permalinks。存档页面中引用的所有文件都已添加到子主题中的站点。
我还为函数添加了注册。php。(见下文)有人能帮忙吗?
以下是存档页面的代码:
<?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();
注册代码
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
)
);
}
SO网友:Mr_Ussi
注册custom\\u post\\u type时也使用此参数。
“public\\u queryable”=>;没错,
那么它应该是这样的。
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
)
);
}