0

I have just been reading up alot about custom taxonomy template files, I have a category within a custom taxonomy that needs its own template.

I understand about the template heirarchy etc.. and seen other posts relating to this.

I think that my file should be named taxonomy-{taxonomy-slug}-{category-slug}.php, is that right?

Though I have already tried taxonomy-ait-dir-item-category-events.php where ait-dir-item-category is the name of the taxonomy and events is the name of the category, changed the page title to make it stand out and it didn't affect anything.

Could someone please advise? Thanks

5

Your terminology is a bit scrambled here. A custom taxonomy is a taxonomy which you manually register through register_taxonomy. In your case that is ait-dir-item-category.

Any "category" (as you call it) you create in your custom taxonomy is called a term. In this case events.

To create a custom page for events, you need to name your template taxonomy-$taxonomy-$term.php. Take a look at the Template Hierarchy

OK, why this won't work in your case. Your taxonomy name is all wrong. You should never use any special characters or capital letters in taxonomy or custom post type names. Only use lowercase letters and underscores (_) in taxonomy names. From the codex:

Name should only contain lowercase letters and the underscore character, and not be more than 32 characters long (database structure restriction).

Lets break down what is happening. Your template name looks like this taxonomy-ait-dir-item-category-events. This is what Wordpress reads when it sees your template:

  • Your taxonomy is called ait and

  • your term is called dir,

  • the rest after dir makes no sense at all.

Wordpress uses a hyphen (-) to separate names, so that is why it reads your template as above. So because the taxonomy ait doesn't exists, Wordpress will default to use the taxonomy.php template. Also, everything after dir makes no sense and doesn't fall into the hierarchy

SOLUTION

You should rename your taxonomy to at least something like ait_dir_item_category and then name your template taxonomy-ait_dir_item_category-events.php

  • 1
    Gave you an upvote for this solution @goose – Brad Dalton Aug 2 '14 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.