{"id":4319,"date":"2018-01-11T15:02:32","date_gmt":"2018-01-11T15:02:32","guid":{"rendered":"https:\/\/ampforwp.com\/tutorials\/?post_type=ht_kb&#038;p=4319"},"modified":"2020-04-27T07:56:40","modified_gmt":"2020-04-27T07:56:40","slug":"create-custom-template-post-type-taxonomy-amp-theme-framework","status":"publish","type":"ht_kb","link":"https:\/\/ampforwp.com\/tutorials\/article\/create-custom-template-post-type-taxonomy-amp-theme-framework\/","title":{"rendered":"Create Custom Template for post type and taxonomy in the AMP Theme Framework"},"content":{"rendered":"<p><strong>An explanation<\/strong> for custom templating for developers. These template supports are available on:<\/p>\n<p><strong>Note:<\/strong> This Tutorial will work only with <a href=\"https:\/\/ampforwp.com\/amp-theme-framework\/\">&nbsp;AMP Theme Framework<\/a>.<\/p>\n<p><strong>Here is the Structured of File:<\/strong><\/p>\n<p><u>Taxonomy: taxonomy.php<\/u><br \/>\n<code>taxonomy-$taxonomy-{$slug_decoded}.php<\/code><br \/>\n<code>taxonomy-$taxonomy-{$term-&gt;slug}.php<\/code><br \/>\n<code>taxonomy-$taxonomy.php<\/code><\/p>\n<p><u>Category: category.php<\/u><br \/>\n<code>category-{$slug_decoded}.php<\/code><br \/>\n<code>category-{$category-&gt;slug}.php<\/code><br \/>\n<code>category-{$category-&gt;term_id}.php<\/code><\/p>\n<p><u>Tag: tag.php<\/u><br \/>\n<code>tag-{$slug_decoded}.php<\/code><br \/>\ntag-{$tag-&gt;slug}.php<br \/>\n<code>tag-{$tag-&gt;term_id}.php<\/code><\/p>\n<p><u>Archive: archive.php<\/u><br \/>\n<code>archive-{$post_type}.php<\/code><br \/>\n<small>Post type archive<\/small><br \/>\n<code>archive-{$post_type}.php<\/code><\/p>\n<p><u>Single: single.php<\/u><br \/>\n<code>single-{$object-&gt;post_type}-{$name_decoded}.php<\/code><br \/>\n<code>single-{$object-&gt;post_type}-{$object-&gt;post_name}.php<\/code><br \/>\n<code>single-{$object-&gt;post_type}.php<\/code><\/p>\n<p><u>Page: page.php<\/u><br \/>\n<code>page-{$pagename_decoded}.php<\/code><br \/>\n<code>page-{$pagename}.php<\/code><br \/>\n<code>page-{$id}.php<\/code><\/p>\n<p><u>Author: author.php<\/u><br \/>\n<code>author-{$author-&gt;user_nicename}.php<\/code><br \/>\n<code>author-{$author-&gt;ID}.php<\/code><\/p>\n<p><code>archive-{post_type}.php<\/code><br \/>\n<code>single-{post_type}.php<\/code><\/p>\n<p><strong>archive-{post_type}.php <\/strong><br \/>\nIf your custom post type were &#8216;product&#8217;, and\/or query_var = &#8220;product&#8221;, AMP Framework would look for archive-product.php to display the archive of posts.<\/p>\n<p>For more details <a href=\"https:\/\/developer.wordpress.org\/themes\/basics\/template-hierarchy\/#custom-post-types\">check in WordPress template hierarchy<\/a><\/p>\n<p><strong>single-{post_type}.php <\/strong><br \/>\nIf your custom post type were &#8216;product&#8217;, and\/or query_var = &#8220;product&#8221;, AMP Framework would look for single-product.php to display the single or permalink of the post.<br \/>\nIts Support <strong>single-{post_type}-{post_name_slug}<\/strong>, <strong>single-{$object-&gt;post_type}<\/strong><\/p>\n<p>For more details <a href=\"https:\/\/developer.wordpress.org\/themes\/basics\/template-hierarchy\/#single-post\">check in WordPress template hierarchy<\/a><\/p>\n<p>For taxonomy also similar like: taxonomy-{taxonomy}-{slug}.php, taxonomy-{taxonomy}.php<\/p>\n<p style=\"background-color: #ffdddd; border-left: 2px solid #f44336; padding: 10px;\"><strong>Note:<\/strong>This might also work with design1, design2, design3&nbsp; but it&#8217;s untested.<\/p>\n<h3><strong>How to create a Custom Template for the custom post type<\/strong><\/h3>\n<p>The following are the steps to create a Custom Template for the custom post type<\/p>\n<p><strong>Step 1:<\/strong><\/p>\n<p>Create a new file with the name \u201csingle-(custom post type slug).php\u201d in your AMP theme Framework directory.<\/p>\n<p>The directory will look like<\/p>\n<p>ex:wp-content\\plugins\\amp-theme-framework<\/p>\n<p><u>Single: single.php<\/u><br \/>\n<code>single-{$object-&gt;post_type}.php<\/code><\/p>\n<p><strong>Step 2:<\/strong><\/p>\n<p>Once you create the file then in that file you need to do all the changes which you want and that customized file will appear for all your custom post types.<\/p>\n<h4 id=\"to-make-it-easy-we-have-created-a-video-tutorial-on-amp-story-that-you-can-watch-below\">To make it easy, we have created a video also<\/h4>\n<div style=\"width: 643px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-4319-1\" width=\"643\" height=\"322\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/05\/Recording-27.mp4?_=1\" \/><a href=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/05\/Recording-27.mp4\">https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/05\/Recording-27.mp4<\/a><\/video><\/div>\n<figure class=\"wp-block-video\">\n<div><\/div>\n<h3 class=\"wp-video\"><strong style=\"color: #17181a; font-size: 20px;\">How to create a Custom Template for <\/strong><strong style=\"color: #17181a; font-size: 20px;\">custom <\/strong><strong style=\"color: #17181a; font-size: 20px;\">taxonomy<\/strong><\/h3>\n<p>The following are the steps to create a Custom Template for the custom taxonomy<\/p>\n<p><strong>Step 1:<\/strong><\/p>\n<p>Create a new file with the name \u201ctaxonomy-(custom post type slug).php\u201d in your AMP theme Framework directory.<\/p>\n<p>The directory will look like<\/p>\n<p>ex:wp-content\\plugins\\amp-theme-framework<\/p>\n<p><u>Taxonomy: taxonomy.php<\/u><br \/>\n<code>taxonomy-$taxonomy.php<\/code><\/p>\n<p><strong>Step 2:<\/strong><\/p>\n<p>Once you create the file then in that file you need to do all the changes which you want and that customized file will appear for all your custom post types.<\/p>\n<h4 id=\"to-make-it-easy-we-have-created-a-video-tutorial-on-amp-story-that-you-can-watch-below\">To make it easy, we have created a video also<\/h4>\n<div>\n<div style=\"width: 643px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-4319-2\" width=\"643\" height=\"322\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/05\/Recording-28.mp4?_=2\" \/><a href=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/05\/Recording-28.mp4\">https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/05\/Recording-28.mp4<\/a><\/video><\/div>\n<\/div>\n<\/figure>\n<h3><strong>How to create <\/strong><strong>a Custom Page Template in AMP Theme Framework.&nbsp;<\/strong><\/h3>\n<p>If you are creating Custom Page Template for Non-AMP version then by default it will not work in AMP and for displaying in AMP you need to copy that custom file and paste it in your AMP Theme Framework directory<\/p>\n<h4>To make it easy, we have created a video also<\/h4>\n<div style=\"width: 643px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-4319-3\" width=\"643\" height=\"323\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/05\/Recording-31.mp4?_=3\" \/><a href=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/05\/Recording-31.mp4\">https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2019\/05\/Recording-31.mp4<\/a><\/video><\/div>\n<p><strong>That\u2019s it for this tutorial!<\/strong><\/p>\n<p>We hope it helped you. If you have any feedback or questions, then please share them in the comments section below.<\/p>\n<div id=\"div-1\" class=\"hkb-feedback\">\n\t\t\t<strong class=\"ht-mobile-exit__title\">Ask your Questions Directly!<\/strong><br>\n\t\t\t<div class=\"hkb_widget_exit__content\" style=\"font-size: 14px;\">If you can't find the solutions in this article, then just ask us in the comments and we will answer it for you!<\/div>\n\t\t\t<a href=\"https:\/\/ampforwp.com\/support\/#contact\" id=\"button\" target=\"_blank\" rel=\"noopener noreferrer\"><button>Yes, I have a Question<\/button><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>An explanation for custom templating for developers. These template supports are available on: Note: This Tutorial will work only with &nbsp;AMP Theme Framework. Here is the Structured of File: Taxonomy: taxonomy.php taxonomy-$taxonomy-{$slug_decoded}.php taxonomy-$taxonomy-{$term-&gt;slug}.php taxonomy-$taxonomy.php Category: category.php category-{$slug_decoded}.php category-{$category-&gt;slug}.php category-{$category-&gt;term_id}.php Tag: tag.php tag-{$slug_decoded}.php tag-{$tag-&gt;slug}.php tag-{$tag-&gt;term_id}.php Archive: archive.php archive-{$post_type}.php Post type archive&#8230;<\/p>\n","protected":false},"author":9,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":[],"ht-kb-category":[186],"ht-kb-tag":[137,138],"_links":{"self":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/4319"}],"collection":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/comments?post=4319"}],"version-history":[{"count":65,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/4319\/revisions"}],"predecessor-version":[{"id":17200,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/4319\/revisions\/17200"}],"wp:attachment":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/media?parent=4319"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb-category?post=4319"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb-tag?post=4319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}