layouteam
layouteam

Reputation: 61

How to use template for a WordPress category?

Here is my code:

$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);

I create in theme phpfile :

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

– If the category’s slug is htfiles-genre, WordPress should look for category-htfiles-genre.php, but he doesn't.

Thanks for any help!

Upvotes: 1

Views: 2033

Answers (2)

Pawan Thakur
Pawan Thakur

Reputation: 591

// You need to save Permalinks again and create following file taxonomy-htfiles_genre.php . Everything will work fine.

Upvotes: 1

Nathan Dawson
Nathan Dawson

Reputation: 19318

The code you've posted is used to register a custom taxonomy which follows a different naming structure to regular categories.

To display a template file for the taxonomy, you need to use taxonomy-{taxonomy}.php. If you wanted to create a template for a given term in that taxonomy, you would use: taxonomy-{taxonomy}-{term}.php.

Your filename should be: taxonomy-htfiles_genre.php.

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

Upvotes: 3

Related Questions