【发布时间】:2020-10-13 12:33:00
【问题描述】:
我无法让自定义帖子类型的单个树枝模板正常工作。
我的 development.twig 页面正确列出了自定义帖子类型开发中的帖子。
但是,单个模板默认为 single.twig,而不是 single-development.twig。 在 single-development.php 我有:
$context = Timber::get_context();
$post = Timber::query_post();
$context['post'] = $post;
Timber::render('single-development.twig', $context);
像其他人建议的那样,我重新保存了永久链接,但这没有帮助。
在 wood-functions.php 我有:
public function register_post_types() {
// Use categories and tags with attachments
register_taxonomy_for_object_type( 'category', 'attachment' );
register_taxonomy_for_object_type( 'post_tag', 'attachment' );
register_post_type('developments', array(
'labels' =>
array(
'name' => __( 'Developments' ),
'singular_name' => __( 'development' )
),
'public' => true,
'supports' => array( 'title', 'author', 'excerpt', 'custom-fields', 'revisions', 'page-attributes' ),
'show_in_menu' => true,
'taxonomies' => array( 'category' ),
));
}
这个结构应该如何工作..我错过了什么吗?
【问题讨论】:
-
我看到您将自定义帖子类型注册为
developments,它是复数形式,末尾带有“s”。这意味着您必须使用 single-developments.php 而不是 single-development.php 作为文件名。