因此,我使用CPT插件创建了一个名为Works的自定义post类型。我设置的弹段代码是proctor-work,我创建了一个名为Archi-Proctor-work.php的模板。我不能让它在http://proctordevelop.wpengine.com/proctor-work上显示,它只是不断地显示404页。我的眼镜蛇红了。存档页面中引用的所有文件都已添加到子主题中的站点中。
我还向functions.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
)
);
} 发布于 2021-02-09 05:01:54
注册custom_post_type时,也要使用这些参数。
'publicly_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
)
);}
https://wordpress.stackexchange.com/questions/383035
复制相似问题