{"id":2461,"date":"2015-06-14T05:04:29","date_gmt":"2015-06-14T05:04:29","guid":{"rendered":"http:\/\/musilda.cz\/?p=2461"},"modified":"2015-06-14T05:04:29","modified_gmt":"2015-06-14T05:04:29","slug":"child-theme-ve-wordpress","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/child-theme-ve-wordpress\/","title":{"rendered":"Child Theme ve WordPress"},"content":{"rendered":"

Na sobotn\u00ed konferenci jsem zd\u016fraz\u0148oval d\u016fle\u017eitost pou\u017eit\u00ed child themes ve WordPressu. Bohu\u017eel se uk\u00e1zalo, \u017ee ne ka\u017ed\u00fd si dovede p\u0159edstavit, jak vlastn\u011b takov\u00e1 child theme funguje.<\/p>\n

Kdy\u017e si na v\u00e1\u0161 web nainstalujete \u0161ablonu, tak takovou \u0161ablonu je mo\u017en\u00e9 aktualizovat, pokud tedy autor n\u011bjakou aktualizaci ud\u011bl\u00e1.<\/p>\n

Nikdo z n\u00e1s v\u0161ak nenajde \u0161ablonu, jen\u017e mu vyhovuje absolutn\u011b. A pokud chcete upravit vzhled webu, z\u00e1sah\u016fm do \u0161ablony se nevyhnete. A\u0165 ji\u017e upravujete css styly, nebo p\u0159\u00edmo k\u00f3d v souborech.<\/p>\n

Po aktualizaci o v\u0161e p\u0159ijdete!<\/h2>\n

P\u0159i aktualizaci se \u0161ablona sma\u017ee a nahraj\u00ed se nov\u00e9 soubory. D\u00edky tomu p\u0159ijdete o v\u00e1my pracn\u011b vyvo\u0159en\u00e9 \u00fapravy a m\u016f\u017eete za\u010d\u00edt znovu. Na\u0161t\u011bst\u00ed v\u00fdvoj\u00e1\u0159i WordPressu vytvo\u0159ili child themes, tak aby jste mohli \u0161ablonu pou\u017e\u00edvat bez obavy ze str\u00e1ty \u00faprav.<\/p>\n

V child \u0161ablon\u011b pak \u0159e\u0161\u00edte jen ty \u010d\u00e1sti k\u00f3du, nebo styl\u016f, jen\u017e chcete upravit. V\u0161e ostatn\u00ed se na\u010d\u00edt\u00e1 z rodi\u010dovsk\u00e9 \u0161ablony.<\/p>\n

Pot\u0159ebujete nap\u0159\u00edklad upravit zobtazov\u00e1n\u00ed titulku detilu str\u00e1nky. V rodi\u010dovsk\u00e9 \u0161ablon\u011b m\u00e1te soubor content-page.php, jen\u017e p\u0159ekop\u00edrujete do slo\u017eky child theme a v n\u011bm uprav\u00edte html k\u00f3d titulku.<\/p>\n

WordPress si nejprve zjist\u00ed, jak\u00e9 soubory jsou v child theme a ty soubory pak ji\u017e v rodi\u010dovsk\u00e9 \u0161ablon\u011b nena\u010d\u00edt\u00e1.<\/p>\n

Jak vytvo\u0159it child theme?<\/h2>\n

Pokud se v\u00e1m nechce \u010d\u00edst n\u00e1vod a rad\u011bji se pod\u00edv\u00e1te na video, jedno jsem nato\u010dil ji\u017e p\u0159e n\u011bjakou dobou a najdete jej na webu wp-see.com<\/a>.<\/p>\n

Ti co rad\u011bji \u010dtou se mohou v\u011bnovat n\u00e1vodu zde v \u010dl\u00e1nku.<\/p>\n

Co budeme pot\u0159ebovat pro child theme?<\/h2>\n

Rodi\u010dovskou \u0161ablonu. Pokud si koup\u00edte \u0161ablonu t\u0159eba na ThemeForest, \u010dasto slo\u017eka, jen\u017e si st\u00e1hnete, obsahuje zip soubor se \u0161ablonou a zip soubor ozna\u010den\u00fd nazev-sablony-child. Pokud ano, m\u00e1te vyhr\u00e1no. Nahrejte ob\u011b slo\u017eky a aktivujte child. M\u00e1te hotovo a d\u00e1l \u010d\u00edst nepot\u0159ebujete.<\/p>\n

Pokud tam ale child nen\u00ed, mus\u00edte si ji vytvo\u0159it. Ve slo\u017ece themes, kde m\u00e1te v\u0161echny \u0161ablony vytvo\u0159te slo\u017eku a nazv\u011bte ji nazev-sablony-child.<\/p>\n

Nyn\u00ed se vra\u0165te do slo\u017eky rodi\u010dovsk\u00e9 \u0161ablony a otev\u0159ete si soubor style.css.<\/p>\n

Na jeho za\u010d\u00e1tku uvid\u00edte tento k\u00f3d:<\/p>\n

\/*\nTheme Name: Test\nTheme URI:\nAuthor: Vladislav Musilek\nAuthor URI: toret.cz\nDescription: Description\nVersion: 1.0.0\nLicense: GNU General Public License v2 or later\nLicense URI: http:\/\/www.gnu.org\/licenses\/gpl-2.0.html\nText Domain: test\nTags:\n*\/\n<\/pre>\n

T\u00e9to \u010d\u00e1sti se \u0159\u00edk\u00e1 stylesheet header a je to \u017eivotn\u011b d\u016fle\u017eit\u00e1 sou\u010d\u00e1st \u0161ablony. WordPress podle t\u00e9to \u010d\u00e1sti k\u00f3du zji\u0161\u0165uje existenci \u0161ablony a informace o n\u00ed. Zde vid\u00edte, \u017ee \u0161ablonu jsme nazvali Test.<\/p>\n

Dal\u0161\u00edm krokem je vytvo\u0159en\u00ed pr\u00e1zdn\u00e9ho css souboru style.css ve slo\u017ece child theme. Soubor nemus\u00ed krom\u011b stylesheet headeru obsahovat \u017e\u00e1dn\u00fd jin\u00fd k\u00f3d. Header je v\u0161ak nutn\u00e9 upravit:<\/p>\n

\n\/*\nTheme Name: Test Child\nTheme URI:\nAuthor: Vladislav Musilek\nAuthor URI: toret.cz\nDescription: Test Child Theme\nVersion: 1.0.0\nLicense: GNU General Public License v2 or later\nLicense URI: http:\/\/www.gnu.org\/licenses\/gpl-2.0.html\nTemplate: parenttheme\nText Domain: test\nTags:\n<\/pre>\n

T\u00edm m\u00e1me p\u0159ipravenou \u0161ablonu tak, \u017ee ji vid\u00edme v administraci a m\u016f\u017eeme ji aktivovat.
\nV\u0161imn\u011bte si rozd\u00edlu, oproti p\u016fvodn\u00edmu z\u00e1pisu, kdy je nav\u00edc polo\u017eka Template. Ta \u0159\u00edk\u00e1, jak\u00e1 \u0161ablona je te rodi\u010dovsk\u00e1. V\u017edy do n\u00ed zapisujeme n\u00e1zev \u0161lo\u017eky rodi\u010dovsk\u00e9 \u0161ablony, nap\u0159\u00edklad Template: avada.<\/p>\n

Co je\u0161t\u011b mus\u00edme ud\u011blat je, \u017ee WordPressu mus\u00edme \u0159\u00edci, odkud m\u00e1 na\u010d\u00edtat css styly pro \u0161ablonu.<\/p>\n

D\u0159\u00edve se to \u0159e\u0161ilo pomoc\u00ed z\u00e1pisu import ve style.css, ale tato metoda je ji\u017e zavr\u017een\u00e1 a spr\u00e1vn\u00fd zp\u016fsob je pomoc\u00ed enqueue.<\/p>\n

Na\u010dten\u00ed css styl\u016f pro child theme<\/h2>\n

Nyn\u00ed mus\u00edme ve slo\u017ece child \u0161ablony vytvo\u0159it soubor functions.php, tedy stejn\u00fd soubor, jen\u017e se nach\u00e1z\u00ed i v rodi\u010dovsk\u00e9 \u0161ablon\u011b.<\/p>\n

Do n\u011bj vlo\u017e\u00edme tento k\u00f3d:
\n(upraveno 4.12.2015 z d\u016fvodu neaktu\u00e1lnosti k\u00f3du)<\/p>\n

\nadd_action( 'wp_enqueue_scripts', 'your_child_theme_enqueue_styles' );\nfunction your_child_theme_enqueue_styles() {\n    \/\/ Parent style id - replace your child theme name\n    $parent_style = 'parent-style';\n\n    \/\/ Enqueue Parent theme's style\n    wp_enqueue_style( $parent_style, get_template_directory_uri() . '\/style.css' );\n    \/\/ Enqueue Child theme's style\n    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '\/style.css', array( $parent_style ) );\n\n\n}\n<\/pre>\n

Hotovo!<\/h2>\n

Child theme m\u00e1te p\u0159ipravenou a m\u016f\u017eete za\u010d\u00edt upravovat \u0161ablonu dle va\u0161ich pot\u0159eb.<\/p>\n

Ur\u010dit\u011b se stane, \u017ee naraz\u00edte na probl\u00e9my, n\u011bkter\u00e9 v\u011bci nejsou \u00fapln\u011b jednoduch\u00e9, ale je to jedin\u00e1 spr\u00e1vn\u00e1 cesta.<\/p>\n

Pozn\u00e1mka:
\nAktu\u00e1ln\u011b je k dispozici p\u0159ipraven\u00e1 child theme, kterou jsi jen st\u00e1hnete, zm\u011bn\u00edte n\u00e1zev slo\u017eky rodi\u010dovsk\u00e9 \u0161ablony a m\u016f\u017eete upravovat –
http:\/\/musilda.cz\/child-theme-snadno-a-rychle\/<\/a><\/p>\n

 <\/p>\n","protected":false},"excerpt":{"rendered":"

Na sobotn\u00ed konferenci jsem zd\u016fraz\u0148oval d\u016fle\u017eitost pou\u017eit\u00ed child themes ve WordPressu. Bohu\u017eel se uk\u00e1zalo, \u017ee ne ka\u017ed\u00fd si dovede p\u0159edstavit, jak vlastn\u011b takov\u00e1 child theme funguje. Kdy\u017e si na v\u00e1\u0161 web nainstalujete \u0161ablonu, tak takovou \u0161ablonu je mo\u017en\u00e9 aktualizovat, pokud tedy autor n\u011bjakou aktualizaci ud\u011bl\u00e1. Nikdo z n\u00e1s v\u0161ak nenajde \u0161ablonu, jen\u017e mu vyhovuje absolutn\u011b.<\/p>\n","protected":false},"author":1,"featured_media":2462,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[12,30,32],"tags":[98],"class_list":["post-2461","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-navody","category-wordpress","category-wordpress-sablony","tag-child-theme"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/2461"}],"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=2461"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/2461\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/2462"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=2461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=2461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=2461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}