Wordpress 木材:archive-post_type.php不燃烧;非木材主题工程中的等效物
使用,我试图为我的自定义帖子类型呈现一个自定义存档页面。CPT是Wordpress 木材:archive-post_type.php不燃烧;非木材主题工程中的等效物,wordpress,timber,Wordpress,Timber,使用,我试图为我的自定义帖子类型呈现一个自定义存档页面。CPT是person,我只是在访问“mysite.com/person”时尝试呈现归档person.php。无论我做什么,我得到的只是archive.php的输出,而不是archive person.php 是的,正如许多人建议的那样,我一直在永久链接上点击“保存” 作为测试,使用WP的2020基本主题,我用经典的WordPress方式制作了一个等价的archive-post_type.php,一切正常。这表明我的cpt和permalink
person
,我只是在访问“mysite.com/person”时尝试呈现归档person.php。无论我做什么,我得到的只是archive.php的输出,而不是archive person.php
是的,正如许多人建议的那样,我一直在永久链接上点击“保存”
作为测试,使用WP的2020基本主题,我用经典的WordPress方式制作了一个等价的archive-post_type.php,一切正常。这表明我的cpt和permalinks还可以,这个问题可能与我的木材主题有关
我已尝试更改我的CPT名称属性,以确保我没有创建永久链接冲突
木材视图/部分、页面、单张和single-post_type.php都呈现良好
除了修补归档*.php页面之外,我应该看的第一件事是什么?在functions.php初始化中,是否存在任何只会影响归档的主要问题
更新:在写这篇文章时,我看到了可能存在的问题。我是否必须通过TimberInit明确注册我的CPT和分类法,以便它能够完全了解它们
archive.php(非常类似于中的一个)
functions.php
class mySite extends Timber\Site {
public function __construct() {
add_theme_support( 'post-thumbnails' );
add_theme_support( 'menus' );
add_filter( 'timber_context', array( $this, 'add_to_context' ) );
parent::__construct();
}
function add_to_context( $context ) {
$context['menu'] = new \Timber\Menu('main-menu');
$context['site'] = $this;
return $context;
}
}
new mySite();
function create_posttypes() {
register_post_type( 'person',
array(
'labels' => array(
'name' => __( 'Persons' ),
'singular_name' => __( 'Person' )
),
'public' => true,
'has_archive' => true,
'show_in_rest' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' )
)
);
}
add_action( 'init', 'create_posttypes' );
对我来说,您所做的似乎已经足够了,但是将其添加到您的functions.php中,以强制标识新的帖子类型
add_action('init', 'person_archive_rewrite');
function person_archive_rewrite(){
add_rewrite_rule('^person/?','index.php?post_type=person','top');
}
然后点击save permalink
保持我的更新我觉得你所做的已经足够了,但是将此添加到你的functions.php以强制识别你的新帖子类型
add_action('init', 'person_archive_rewrite');
function person_archive_rewrite(){
add_rewrite_rule('^person/?','index.php?post_type=person','top');
}
然后点击save permalink
保持我的最新状态尝试过,但仍然没有更改。尝试过,但仍然没有更改。
add_action('init', 'person_archive_rewrite');
function person_archive_rewrite(){
add_rewrite_rule('^person/?','index.php?post_type=person','top');
}