Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have registered a custom post type [equipment] and have a taxonomy of [equipment_type] within the taxonomy I have parent and child categories. For example:

Equipment (Custom post type)

Equipment Types (Taxonomy)

Cameras (Parent term)

  • Camera A (Child term)

  • Camera B

What I would like to create is effectively an archive page for the taxonomy terms. So when either 'Cameras' or 'Camera A' is selected it shows say 12 posts with title and featured image (links to single post) plus some pagination.

I have tried a standard WP query and Loop and it always ends up showing all of the taxonomies posts in all terms.

I currently have a taxonomy-equipment_types.php template set up to handle the query.

share|improve this question
Please explain what you mean by Taxonomy Category. Your question conflates taxonomy and category (which is one type of taxonomy). Are you saying that you have hierarchical terms for your custom taxonomy, equipment_type? Also, is cameras a term for the equipment_type taxonomy? – Chip Bennett Dec 7 '12 at 19:00
My apologies, perhaps I am confusing the terminology. I have a taxonomy of 'equipment_type' and within that I have 'cameras', 'lenses' etc... are those terms? They are Hierarchical and act like categories would on posts within the standard WP setup. – user1833715 Dec 7 '12 at 19:07
Ah, now you have it! cameras, lenses, camera-a, and camera-b are terms of the equipment_type taxonomy. The camera-a and camera-b terms are children of the cameras term. – Chip Bennett Dec 7 '12 at 19:45
Thank you for clarifying toscho I appreciate it. – user1833715 Dec 7 '12 at 19:48

1 Answer

The WordPress Template Hierarchy provides the exact template file that you need: taxonomy-{taxonomy}-{term}.php.

So, to create a custom template for the cameras term of the equipment_types taxonomy, you would create a file named taxonomy-equipment_types-cameras.php.

(Note, you can also create a template file for the taxonomy itself; just omit the {term} slug: taxonomy-{taxonomy}.php, or taxonomy-equipment_types.php in your case.)

You can conditionally output content based on hierarchy by querying for either the term parent, via the object properties returned by get_term(), or the term children, via get_term_children().

share|improve this answer
Thanks Chip, I thought the WP template provided what I needed as you suggested: taxonomy-equipment_types.php I think where I am struggling is working out how to output the content / posts based on the user selected terms for both parent and or child, cameras or cameras-a. Are suggesting I use 'get_term()' to decipher which content / posts should output in the loop? I'm fairly new to PHP and currently learning through Lynda.com. So I'm going to have to delve in a little more and try to understand the process. Could you provide a rough example to help me understand what I need to do? – user1833715 Dec 8 '12 at 13:10

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.