0

I have a custom post type, Vehicles. Vehicles have a custom taxonomy, new or used. Naturally the vehicle pages use single-vehicles.php but I would like to differentiate between new and used vehicles by somehow using different templates automatically based on whether they're new or used.

For example, the New vehicles don't have certain attributes (Mileage, Year etc) as they're not relevant, so I would like to remove that from their template.

If this is possible, that would be great. If not I'd really appreciate any alternative ways around it.

  • You should really use post meta fields for boolean properties. Each post might be a member of multiple terms; in your case: a vehicle could be new and used at once. – fuxia Jun 21 '13 at 9:46
0

I'm afraid you have to do this manually. You can put someting like this in your single-vehicles.php file:

if ( ... ) { // check if it's in used category/term
    get_template_part('part-single-vehicles-used');
} else {
    get_template_part('part-single-vehicles-new');
}

And then put new car template into part-single-vehicles-new.php file and used car template into part-single-vehicles-used.php.

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.