{"id":3321,"date":"2016-11-01T10:06:02","date_gmt":"2016-11-01T10:06:02","guid":{"rendered":"http:\/\/musilda.cz\/?p=3321"},"modified":"2016-11-01T10:06:02","modified_gmt":"2016-11-01T10:06:02","slug":"dve-nove-funkce-filter-tvurce-sablon-ve-wordpress-4-7","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/dve-nove-funkce-filter-tvurce-sablon-ve-wordpress-4-7\/","title":{"rendered":"Dv\u011b nov\u00e9 funkce a filter pro tv\u016frce \u0161ablon ve WordPress 4.7"},"content":{"rendered":"
Mezi dal\u0161\u00edmi novinkami, kter\u00e9 p\u0159in\u00e1\u0161\u00ed WordPress 4.7, jsou i dv\u011b nov\u00e9 funkce a nov\u00fd filter, ur\u010den\u00e9 pro v\u00fdvoj\u00e1\u0159e \u0161ablon.<\/p>\n
Speci\u00e1ln\u011b pro vytv\u00e1\u0159en\u00ed child themes, jsou ur\u010deny dv\u011b nov\u00e9 funkce get_theme_file_uri<\/strong> a get_theme_file_path<\/strong>.<\/p>\n Jedn\u00edm z nepostradateln\u00fdch prvk\u016f, p\u0159i vytv\u00e1\u0159en\u00ed odvozen\u00fdch \u0161ablon, je funkce get_template_part. Funguje pom\u011brn\u011b jednodu\u0161e. Nap\u0159\u00edklad:<\/p>\n hled\u00e1 nejprve soubor page-content.php, nejprve v child theme a pokud jej nenajde, hled\u00e1 soubor v parent theme. D\u00edky tomu, m\u016f\u017eete jednodu\u0161e nahrazovat soubory rodi\u010dovsk\u00e9 \u0161ablony.<\/p>\n U css a js soubor\u016f to zat\u00edm bylo tak, \u017ee jste je museli nejprve odregistrovat a n\u00e1sledn\u011b vlo\u017eit v\u00e1\u0161 upraven\u00fd soubor.<\/p>\n Get_theme_file_uri<\/strong> p\u0159in\u00e1\u0161\u00ed do v\u00fdvoje \u0161ablon, p\u0159esn\u011b ten mechanismus, jako u get_template_part.<\/p>\n M\u016f\u017eeme tak velmi lehce nap\u0159\u00edklad v child \u0161ablon\u011b nahradit javascriptov\u00fd soubor, v n\u011bm\u017e pot\u0159ebujeme ud\u011blat \u00fapravy.<\/p>\n Nav\u00edc, na rozd\u00edl od\u00a0get_template_directory_uri, je mo\u017en\u00e9 jako parametr funkce zadat samotn\u00fd soubor. Nav\u00edc je zde filtr theme_file_uri, kter\u00fd umo\u017en\u00ed manipulovat s vkl\u00e1dan\u00fdmi soubory pomoc\u00ed plugin\u016f.<\/p>\n Ekvivalentem k t\u00e9to nov\u00e9 funkci je get_theme_file_path.<\/p>\n P\u0159esto\u017ee m\u016f\u017eete s hierarchi\u00ed \u0161ablony manipulovat pomoc\u00ed filtru template_include, v nov\u00e9m WordPressu budou p\u0159id\u00e1ny nov\u00e9 filtry, jen\u017e umo\u017en\u00ed manipulovat s hierarchi\u00ed \u0161ablony na \u00farovni konkr\u00e9tn\u00edho typu souboru \u0161ablony.<\/p>\n Pokud nap\u0159\u00edklad budete cht\u00edt zm\u011bnit hierarchii v arch\u00edvech, vypisuj\u00edc\u00ed posty podle data, m\u016f\u017eete postupovat takto:<\/p>\n V p\u0159\u00edpad\u011b, \u017ee nem\u00e1te p\u0159esnou p\u0159edstavu o fungov\u00e1n\u00ed hierarchie v \u0161ablon\u00e1ch, rad\u011bji se t\u011bmto \u00faprav\u00e1m vyhn\u011bte.<\/p>\n Filtry, jen\u017e m\u016f\u017eete pou\u017e\u00edt:<\/p>\n Mezi dal\u0161\u00edmi novinkami, kter\u00e9 p\u0159in\u00e1\u0161\u00ed WordPress 4.7, jsou i dv\u011b nov\u00e9 funkce a nov\u00fd filter, ur\u010den\u00e9 pro v\u00fdvoj\u00e1\u0159e \u0161ablon. Speci\u00e1ln\u011b pro vytv\u00e1\u0159en\u00ed child themes, jsou ur\u010deny dv\u011b nov\u00e9 funkce get_theme_file_uri a get_theme_file_path. Jedn\u00edm z nepostradateln\u00fdch prvk\u016f, p\u0159i vytv\u00e1\u0159en\u00ed odvozen\u00fdch \u0161ablon, je funkce get_template_part. Funguje pom\u011brn\u011b jednodu\u0161e. Nap\u0159\u00edklad: get_template_part(‚page‘ ‚content‘) hled\u00e1 nejprve soubor page-content.php, nejprve v<\/p>\n","protected":false},"author":1,"featured_media":8523,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,30],"tags":[177,178,469],"class_list":["post-3321","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-novinky","category-wordpress","tag-get_theme_file_path","tag-get_theme_file_uri","tag-wordpress-4-7"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/3321"}],"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=3321"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/3321\/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=3321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=3321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=3321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}get_template_part('page' 'content')<\/pre>\n
wp_enqueue_script( <\/code>
'my-script'<\/code>
, get_theme_file_uri( <\/code>
'js\/my-script.js'<\/code>
) );<\/code><\/p>\n
{$type}_template_hierarchy filter<\/strong><\/h2>\n
add_filter( <\/code>
'date_template_hierarchy'<\/code>
, <\/code>
function<\/code>
( <\/code>
array<\/code>
$templates<\/code>
) {<\/code><\/div>\n
\u00a0\u00a0\u00a0\u00a0<\/code>
$year<\/code>
= get_query_var( <\/code>
'year'<\/code>
);<\/code><\/div>\n
\u00a0\u00a0\u00a0\u00a0<\/code>
array_unshift<\/code>
( <\/code>
$templates<\/code>
, <\/code>
\"year-{$year}.php\"<\/code>
);<\/code><\/div>\n
\u00a0\u00a0\u00a0\u00a0<\/code>
return<\/code>
$templates<\/code>
;<\/code><\/div>\n
} );<\/code><\/div>\n
\n
embed_template_hierarchy<\/code><\/li>\n
404_template_hierarchy<\/code><\/li>\n
search_template_hierarchy<\/code><\/li>\n
frontpage_template_hierarchy<\/code><\/li>\n
home_template_hierarchy<\/code><\/li>\n
taxonomy_template_hierarchy<\/code><\/li>\n
attachment_template_hierarchy<\/code><\/li>\n
single_template_hierarchy<\/code><\/li>\n
page_template_hierarchy<\/code><\/li>\n
singular_template_hierarchy<\/code><\/li>\n
category_template_hierarchy<\/code><\/li>\n
tag_template_hierarchy<\/code><\/li>\n
author_template_hierarchy<\/code><\/li>\n
date_template_hierarchy<\/code><\/li>\n
archive_template_hierarchy<\/code><\/li>\n
paged_template_hierarchy<\/code><\/li>\n
index_template_hierarchy<\/code><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"