类别-slug.php 不工作

category-slug.php not working

这是我的代码:

$config = array(
    'labels'            => $genre_labels,
    'hierarchical'      => true,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'htfiles-genre' ),
    );

register_taxonomy('htfiles_genre', array('htfiles'), $config);

我在主题 phpfile 中创建:

Category-htfiles-genre.php
category-{slug}.php

– 如果类别的别名是 htfiles-genre,WordPress 应该寻找 category-htfiles-genre.php。 但他没有。

感谢您的帮助!

您发布的代码用于注册自定义分类法,该分类法遵循与常规类别不同的​​命名结构。

要显示分类的模板文件,您需要使用 taxonomy-{taxonomy}.php。如果您想为该分类法中的给定术语创建模板,您可以使用:taxonomy-{taxonomy}-{term}.php.

您的文件名应该是:taxonomy-htfiles_genre.php.

文档:https://developer.wordpress.org/themes/basics/template-hierarchy/#custom-taxonomies

// 您需要再次保存永久链接并创建以下文件分类法-htfiles_genre.php。一切都会好的。