Support

Account

Home Forums Front-end Issues Get_template variation

Solving

Get_template variation

  • Hi

    I want to display a get_template part when some products have a specific taxonomy, and another for all other products.

    Example product page for a bed: https://www.dunlopillo.dk/produkter/dunlopillo-button

    At the moment i have a static get_template part on all products which work fine, but the client wants a variation.

    I want to display this on all pages with a bed product:
    get_template_part( ‘partials/sections/section’, ‘unikke-egenskaber-fleksibilitet’ );

    and this for all the remaining products:
    get_template_part( ‘partials/sections/section’, ‘unikke-egenskaber-7-komfortzoner’ );

    How do i write the correct if code? I don’t have much experience with php, but i understand the fundamentals of programming, so i need some help creating the correct snippet to include in my template file.

    Thanks!

  • You need to check the taxonomy/term of the product and then load a different template part based on that check.

    
    if ($condition) {
      get_template_part('special');
    } else {
      get_template_part('standard');
    }
    

    How you would check the term of the taxonomy would depend on the template and what variables you have to work with but would involve using wp_get_object_terms() https://codex.wordpress.org/Function_Reference/wp_get_object_terms

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Get_template variation’ is closed to new replies.