Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I created the taxonomy 'machine types', and added several terms to it, like 'cranes' for example.

The url to that term now looks like this: domain.com/machine-types/cranes

How can I make this url query for only posts with the term cranes? And the same for all other terms, without creating a template for each term.

I think I must ask for the current term and store it in a value, and query for that, right? How?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You can create a taxonomy.php file and put your loop/query inside this file and as such anytime you are on a taxonomy page, no matter the term, be it cranes, bulldozers, etc the taxonomy.php will take over and handle the term in question (as shown in your URL).

Taken from the WordPress Codex, this is the template hierarchy - the order in which what files take precedence over another for taxonomy pages.

Custom Taxonomies display


  • taxonomy-{taxonomy}-{slug}.php - If the taxonomy were sometax, and taxonomy's slug were someterm WordPress would look for taxonomy-sometax-someterm.php. In the case of Post Formats, the taxonomy is 'post_format' and the terms are 'post-format-{format}. i.e. taxonomy-post_format-post-format-link.php

  • taxonomy-{taxonomy}.php - If the taxonomy were sometax, WordPress would look for taxonomy-sometax.php

  • taxonomy.php

  • archive.php

  • index.php

So as you can see if you need to you can also customize the template file right up to the individual taxonomy term, or taxonomy (if you have more than one).

share|improve this answer
    
Thanks. I have several different taxonomies which I might want to display differently, so I ended up using taxonomy-mytaxonomy.php. –  Johan Dahl Jun 20 '12 at 12:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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