{"id":9841,"date":"2013-05-23T17:47:53","date_gmt":"2013-05-23T17:47:53","guid":{"rendered":"http:\/\/musilda.cz\/?p=454"},"modified":"2013-05-23T17:47:53","modified_gmt":"2013-05-23T17:47:53","slug":"funkce-get_template_part","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/funkce-get_template_part\/","title":{"rendered":"Funkce get_template_part"},"content":{"rendered":"

Vkl\u00e1d\u00e1 do \u0161ablony dal\u0161\u00ed \u010d\u00e1st \u0161ablony, jinou, ne\u017e header, footer a sidebar. Je zp\u016fsobem, jak jednodu\u0161e vkl\u00e1dat \u010d\u00e1sti k\u00f3du do \u0161ablony v z\u00e1vislosti na r\u016fzn\u00fdch funkc\u00edch. D\u00edky tomu m\u016f\u017eete upravovat vzhled podle zobrazen\u00e9 kategorie, na\u010d\u00edtat r\u016fzn\u00e9 druhy hlavi\u010dek a jin\u00fdch \u010d\u00e1st\u00ed webu. V\u00fdborn\u00fdm p\u0159\u00edkladem je zobrazov\u00e1n\u00ed post types podle toho, o jak\u00fd druh se jedn\u00e1.<\/p>\n

Pou\u017eit\u00ed v \u0161ablon\u011b je n\u00e1sleduj\u00edc\u00ed:<\/p>\n

get_template_part( $slug, $name );<\/pre>\n

Parametr $slug ur\u010duje cestu k souboru, kter\u00fd budeme cht\u00edt zobrazit.
\nParametr $name specifikuje jm\u00e9no specializovan\u00e9 template.<\/p>\n

P\u0159\u00edklad pou\u017eit\u00ed:<\/h3>\n

Nad v\u00fdpisem obsahu budeme m\u00edt blok, kter\u00fd by se m\u011bl m\u011bnit podle toho, zda budeme na indexu, kategorii, na str\u00e1nce, nebo postu. Ve slo\u017ece template si vytvo\u0159\u00edme slo\u017eku, kterou nazveme top-block a do n\u00ed vlo\u017e\u00edme soubor s n\u00e1zvem block.php. Ten se n\u00e1m bude zobrazovat v p\u0159\u00edpad\u011b, \u017ee \u0161ablona nenajde specializovan\u00fd soubor pro danou situaci.<\/p>\n

Zobrazen\u00ed pro index:<\/strong><\/p>\n

get_template_part( 'top-block\/block', 'index' );<\/pre>\n

Ze slo\u017eky top-block bude \u0161ablona hledat soubor block-index.php. V n\u011bm by m\u011bl b\u00fdt k\u00f3d, kter\u00fd chcete zobrazovat pouze na indexu. Pokud jej nenajde, zobraz\u00ed block.php. Pro ostatn\u00ed p\u0159\u00edklady to je obdobn\u00e9.<\/p>\n

Zobrazen\u00ed pro kategorii:<\/strong><\/p>\n

get_template_part( 'top-block\/block', 'category' );<\/pre>\n

Soubor block-category.php<\/p>\n

Zobrazen\u00ed pro str\u00e1nku:<\/strong><\/p>\n

get_template_part( 'top-block\/block', 'page' );<\/pre>\n

Soubor block-page.php<\/p>\n

Zobrazen\u00ed pro \u010dl\u00e1nek:<\/strong><\/p>\n

get_template_part( 'top-block\/block', 'single' );<\/pre>\n

Soubor block-single.php<\/p>\n

Zobrazen\u00ed pro arch\u00edv:<\/strong><\/p>\n

get_template_part( 'top-block\/block', 'archive' );<\/pre>\n

block-archive.php<\/p>\n","protected":false},"excerpt":{"rendered":"

Vkl\u00e1d\u00e1 do \u0161ablony dal\u0161\u00ed \u010d\u00e1st \u0161ablony, jinou, ne\u017e header, footer a sidebar. Je zp\u016fsobem, jak jednodu\u0161e vkl\u00e1dat \u010d\u00e1sti k\u00f3du do \u0161ablony v z\u00e1vislosti na r\u016fzn\u00fdch funkc\u00edch. D\u00edky tomu m\u016f\u017eete upravovat vzhled podle zobrazen\u00e9 kategorie, na\u010d\u00edtat r\u016fzn\u00e9 druhy hlavi\u010dek a jin\u00fdch \u010d\u00e1st\u00ed webu. V\u00fdborn\u00fdm p\u0159\u00edkladem je zobrazov\u00e1n\u00ed post types podle toho, o jak\u00fd druh se jedn\u00e1.<\/p>\n","protected":false},"author":1,"featured_media":8523,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,22],"tags":[176,483],"class_list":["post-9841","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codex","category-template-tags","tag-get_template_part","tag-wordpress-codex"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/9841"}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=9841"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/9841\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/8523"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=9841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=9841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=9841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}