{"id":2019391,"date":"2021-04-13T11:51:45","date_gmt":"2021-04-13T11:51:45","guid":{"rendered":"https:\/\/toolset.com\/?post_type=course-lesson&#038;p=2019391"},"modified":"2021-04-14T13:40:41","modified_gmt":"2021-04-14T13:40:41","slug":"assigning-templates-to-posts-conditionally","status":"publish","type":"course-lesson","link":"https:\/\/toolset.com\/es\/course-lesson\/assigning-templates-to-posts-conditionally\/","title":{"rendered":"Assigning Templates to Posts Conditionally"},"content":{"rendered":"\n<p>Let\u2019s say you have a WooCommerce store for selling shoes and you have product categories for \u201cTrainers\u201d and \u201cHeels\u201d. You can assign a different template to display single trainer shoes and another one for heels shoes.<\/p>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid tb-grid\" data-toolset-blocks-grid=\"3d9c399fe625e1b972f817a0680229f6\">\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"3034fbe886c11054e95b46b09d3e4112\">\n<p><strong>Template for displaying shoes in the \u201cTrainer\u201d category<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image tb-image tb-image-dynamic\" data-toolset-blocks-image=\"4a9c8517bf4f08a59b126ef98fcfe3dc\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/04\/toolset-conditional-templates-example2.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/04\/toolset-conditional-templates-example2-360x310.png\" alt=\"\" class=\"wp-image-2010495\"\/><\/a><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"3034fbe886c11054e95b46b09d3e4112\">\n<p><strong>Template for displaying shoes in the \u201cHeels\u201d category<\/strong><br><\/p>\n\n\n\n<figure class=\"wp-block-image tb-image tb-image-dynamic\" data-toolset-blocks-image=\"6d9eb9df059b833850ac27dd418d60df\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/04\/toolset-conditional-templates-example1.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/04\/toolset-conditional-templates-example1-360x310.png\" alt=\"\" class=\"wp-image-2010545\"\/><\/a><\/figure>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Steps for assigning a template conditionally<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Create a new <a href=\"https:\/\/toolset.com\/glossary\/template\/\" target=\"_blank\" rel=\"noreferrer noopener\">Content Template<\/a> or edit an existing one.<\/li><li>Under the <strong>Usage <\/strong>section in the right sidebar, make sure the template is assigned to a post type. <\/li><li>Click the <strong>Set conditions<\/strong> link next to the post type&#8217;s name.<\/li><li>Set your conditions using the dropdown menus in a pop-up dialog that appears. You can select conditions based on the available fields and taxonomies for the selected post type.<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-dynamic aligncenter\" data-toolset-blocks-image=\"ff2813c0d308b297b81bdd364b3fb217\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/04\/toolset-conditional-templates-dialog-example.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/04\/toolset-conditional-templates-dialog-example-500x205.png\" alt=\"Dialog for setting up a conditional display for a Content Template\" class=\"wp-image-2010557\"\/><\/a><\/figure>\n<\/div>\n\n\n<ol class=\"wp-block-list\" start=\"5\"><li>When done setting up the condition(s) click the <strong>Accept <\/strong>button.<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Setting the template priority<\/h3>\n\n\n\n<p>Sometimes, you might conditionally assign multiple templates to the same content. In this case, you need to set the template&#8217;s priority:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Expand the <strong>Priority <\/strong>section in the right sidebar.<\/li><li>Use the <strong>Template Priority<\/strong> field to set the desired priority for the conditional template. Higher number means higher priority.<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-dynamic aligncenter\" data-toolset-blocks-image=\"c05a5b0687eda6bb592bb9644c9b2b99\"><img decoding=\"async\" width=\"279\" height=\"623\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/04\/toolset-content-template-conditional-priority-2.png\" alt=\"\" class=\"wp-image-2019537\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/04\/toolset-content-template-conditional-priority-2.png 279w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/04\/toolset-content-template-conditional-priority-2-134x300.png 134w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/04\/toolset-content-template-conditional-priority-2-67x150.png 67w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/04\/toolset-content-template-conditional-priority-2-233x520.png 233w\" sizes=\"auto, (max-width: 279px) 100vw, 279px\" \/><div class=\"tb-image-caption\"><figcaption>Setting the priority of a Content Template<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Conditions based on product&#8217;s stock status<\/h2>\n\n\n\n<p>You can set up the conditions based on the stock status of a product. Currently, you need to manually enter the value you want to check against.<\/p>\n\n\n\n<p>Use the following values when setting up conditions based on stock status:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>instock <\/strong>&#8211; is true when the product is in stock<\/li><li><strong>outofstock <\/strong>&#8211; is true when the product is out of stock<\/li><li><strong>onbackorder <\/strong>&#8211; is true when the product is on backorder<\/li><\/ul>\n\n\n\n<p>For stock status to work, you need to manually enable the stock management option for all relevant products.<\/p>\n","protected":false},"author":4341,"featured_media":2020413,"template":"","related-lesson":[8445,8427],"class_list":["post-2019391","course-lesson","type-course-lesson","status-publish","has-post-thumbnail","hentry","related-lesson-e-commerce","related-lesson-post-templates"],"_links":{"self":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson\/2019391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson"}],"about":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/types\/course-lesson"}],"author":[{"embeddable":true,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/users\/4341"}],"version-history":[{"count":8,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson\/2019391\/revisions"}],"predecessor-version":[{"id":2023437,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson\/2019391\/revisions\/2023437"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/media\/2020413"}],"wp:attachment":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/media?parent=2019391"}],"wp:term":[{"taxonomy":"related-lesson","embeddable":true,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/related-lesson?post=2019391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}