[英]Custom Post Type archive page not being used in Timber/Twig WordPress setup
問題:我們的 WordPress 安裝使用 archive.php 作為存檔頁面,而不是所需的 archive-article.php。
這是我們的配置:
函數.php
register_post_type(
'article',
array(
'labels' => array(
'name' => __('Articles'),
'singular_name' => __('Article'),
),
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-media-default',
'menu_position' => 4,
'taxonomies' => array('article_type'),
'supports' => array('title', 'editor', 'custom-fields', 'page-attributes', 'thumbnail')
)
);
歸檔-article.php
<?php
/**
* The template for displaying Archive pages.
*
* Used to display archive-type pages if nothing more specific matches a query.
* For example, puts together date-based pages if no date.php file exists.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.2
*/
$templates = array( 'archive-article.twig', 'index.twig' );
$context = Timber::context();
$args = array(
'post_type' => 'article',
'posts_per_page' => '-1'
);
$context['title'] = 'Archive: Article';
$context['categories'] = $post->terms( array(
'query' => [
'taxonomy' => 'article_type',
],
) );
$context['article'] = new \Timber\PostQuery($args);
Timber::render( $templates, $context );
任何來自第二雙眼睛的幫助將不勝感激!
除了 has_archive 之外,嘗試將存檔 slug 添加到您的自定義帖子注冊?
"rewrite" => array("slug" => "articles"),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.