vendredi 5 avril 2019

variable template parts on product pages wordpress website

I need to display one of two template parts inside a product page. Depending on what taxonomy the product has it needs to display one or the other.

2nd from the bottom is where the block displays, called "7 komforzoner": https://www.dunlopillo.dk/produkter/natura-continental#

ATM all the pages display the same static block via:

<?php get_template_part( 'partials/sections/section', 'unikke-egenskaber-7-komfortzoner' ); ?>

How can display this or the other depending on what taxonomy the product has?

I've looked and tried several php statements, but i only get a blank page.

I haven't saved the snippets, but something like:

<?php if ( has_term(‘produkttyper’,’senge’ ) ) {
get_template_part( 'partials/sections/section', 'unikke-egenskaber-fleksibilitet’ );
} elseif (has_term(‘produkttyper’,’supplement’, ‘puder’ ) ) {
get_template_part( 'partials/sections/section', 'unikke-egenskaber-fleksibilitet’ );}
endif; ?>

On pages containing beds I need to display this template part:

<?php get_template_part( 'partials/sections/section', 'unikke-egenskaber-fleksibilitet' ); ?>

On pages containing every other product display this:

<?php get_template_part( 'partials/sections/section', 'unikke-egenskaber-7-komfortzoner' ); ?>

Aucun commentaire:

Enregistrer un commentaire