我努力讓我的自定義後類型使用個性化的檔案模板,希望有人能看到我要去哪裏錯了,幫我重回正軌嗎?WordPress的自定義文章類型與類別檔案頁
這裏是我用於創建自定義文章類型代碼:
add_action('init', 'news_post_type');
function news_post_type() {
register_post_type('news',
array(
'labels' => array(
'name' => __('News'),
'singular_name' => __('News')
),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'public' => true,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','revisions','thumbnail','author','page-attributes',)
)
);
}
register_taxonomy('news_category', 'news',array('label' => __('Categories'),'rewrite' => array('slug' => 'news/category'),'hierarchical' => true,));
這是偉大的URL回報:www.mysite.com/news/category/%the_category%就像我想。
問題是我希望此CPT中的每個類別都使用我的自定義模板,但是當我創建一個名爲archive-news.php
的文件時,它將被忽略。但是,如果我創建一個名爲archive.php
的文件,那麼它可以工作,但顯然這適用於我不想要的所有其他文章歸檔。
我不是正確命名模板文件?我是如何創建CPT的錯誤?
如果有人可以幫助將不勝感激。
非常感謝
https://codex.wordpress.org/Category_Templates '類別的slug.php, 品類ID.php, category.php, archive.php, index.php' –
重命名文件類別-news.php沒有工作範疇的任何:( – Ordog
嘗試ID,或在你的archive.php做這樣的事' https://developer.wordpress.org/reference/functions/get_template_part/ –