{"id":9825,"date":"2013-05-09T13:29:33","date_gmt":"2013-05-09T13:29:33","guid":{"rendered":"http:\/\/musilda.cz\/?p=343"},"modified":"2013-05-09T13:29:33","modified_gmt":"2013-05-09T13:29:33","slug":"jak-vytvorit-v-sablone-editovatelne-menu","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-vytvorit-v-sablone-editovatelne-menu\/","title":{"rendered":"Jak vytvo\u0159it v \u0161ablon\u011b editovateln\u00e9 menu"},"content":{"rendered":"\n

V\u0161echny WordPress \u0161ablony vyu\u017e\u00edvaj\u00ed vytv\u00e1\u0159en\u00ed menu pomoc\u00ed rozhran\u00ed v administraci, kter\u00e9 najdete v nastaven\u00ed Vzhled, polo\u017eka Menu. P\u0159esto\u017ee se jedn\u00e1 o b\u011b\u017enou a pou\u017e\u00edvanou v\u011bc, dnes si uk\u00e1\u017eeme, jak si vytvo\u0159it dal\u0161\u00ed m\u00edsto v \u0161ablon\u011b, kam m\u016f\u017eeme um\u00edstit jak\u00e9koliv menu.<\/p>\n\n\n\n\n\n\n\n

V nastaven\u00ed menu v lev\u00e9m sloupci m\u016f\u017eete vid\u011bt n\u00e1sleduj\u00edc\u00ed dialog:<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Pokud tomu tak nen\u00ed, va\u0161e \u0161ablony nepodporuje um\u00edst\u011bn\u00ed menu do definovan\u00e9 oblasti. D\u00edky tomuto n\u00e1vodu ji v\u0161ak m\u016f\u017eete vytvo\u0159it. J\u00e1 ale p\u0159edpokl\u00e1d\u00e1m, \u017ee \u0161ablona m\u00e1 definovanou minim\u00e1ln\u011b jednu oblast pro um\u00edst\u011bn\u00ed menu. V souboru functions.php by jste tedy m\u011bli m\u00edt tento k\u00f3d:<\/p>\n\n\n\n

add_theme_support( 'menus' );\nif ( function_exists( 'register_nav_menus' ) ) {\n\tregister_nav_menus(\n\t\tarray(\n\t\t  'primary-menu' => 'Primary Menu'\n\t\t)\n\t);\n}\n<\/pre>\n\n\n\n

Funkce add_theme_support() umo\u017e\u0148uje pou\u017e\u00edvat pluginu, nebo \u0161ablon\u011b definovanou Theme Features<\/a>, v na\u0161em p\u0159\u00edpad\u011b \u00fapravu menu v administraci. K vlastn\u00ed registraci oblasti pro menu vyu\u017eijeme funkci register_nav_menus(), kter\u00e1 m\u00e1 jeden argument a to $locations, tedy n\u00e1zev lokace, kde bude menu um\u00edst\u011bno. P\u0159edchoz\u00ed k\u00f3d vytv\u00e1\u0159\u00ed v \u0161ablon\u011b m\u00edsto pro jedno menu, kter\u00e9 se zobrazuje, \u0159ekn\u011bme na spodn\u00ed stran\u011b headeru. My si vytvo\u0159\u00edme jedno menu nad headerem a jedno do pati\u010dky. Toto berte jako p\u0159\u00edklad, z\u00e1le\u017e\u00ed jen na v\u00e1s, kam si menu v \u0161ablon\u011b um\u00edst\u00edte.<\/p>\n\n\n\n

V functions.php nahrad\u00edme p\u0159edchoz\u00ed m\u00edrn\u011b upraven\u00fdm k\u00f3dem:<\/p>\n\n\n\n

add_theme_support( 'menus' );\nif ( function_exists( 'register_nav_menus' ) ) {\n\tregister_nav_menus(\n\t\tarray(\n\t\t  'primary-menu' => 'Primary Menu',\n      'secondary-menu' => 'Secondary Menu',\n      'footer-menu' => 'Footer Menu'\n\t\t)\n\t);\n}\n<\/pre>\n\n\n\n

V administrace se n\u00e1m zobraz\u00ed toto:<\/p>\n\n\n\n

\"\"<\/a><\/figure>\n\n\n\n

Jak vid\u00edte, zobrazili se n\u00e1m dal\u0161\u00ed oblasti. Kdy\u017e vytvo\u0159\u00edme dal\u0161\u00ed menu, kter\u00e9 um\u00edst\u00edme, mus\u00edme jej vlo\u017eit do \u0161ablony. pou\u017eijeme funkci wp_nav_menu. Ta m\u00e1 pom\u011brn\u011b hodn\u011b parametr\u016f, doporu\u010duji nahl\u00e9dnout do codexu<\/a>.
\nN\u00e1m bude sta\u010dit n\u00e1sleduj\u00edc\u00ed k\u00f3d:<\/p>\n\n\n\n

if ( has_nav_menu( 'primary-menu' ) ) {\nwp_nav_menu( array(\n      'theme_location' => 'primary-menu', 'menu_class' => 'menu', 'container' => ''\n       ) );\n } else {\necho '
    ';\n wp_list_categories('title_li=');\necho '<\/ul>';\n }\n<\/pre>\n\n\n\n

    Nejprve zjist\u00edme, zda existuje primary-menu. Pokud ne, vyp\u00ed\u0161eme seznam v\u0161ech kategori\u00ed. Pokud ano, vyp\u00ed\u0161eme menu. Jednoduchou obm\u011bnou, zm\u011bn\u00edme primary na secondary a tak d\u00e1le dle um\u00edst\u011bn\u00ed v \u0161ablon\u011b.<\/p>\n\n\n\n

    A to je v\u0161e.<\/p>\n","protected":false},"excerpt":{"rendered":"

    V\u0161echny WordPress \u0161ablony vyu\u017e\u00edvaj\u00ed vytv\u00e1\u0159en\u00ed menu pomoc\u00ed rozhran\u00ed v administraci, kter\u00e9 najdete v nastaven\u00ed Vzhled, polo\u017eka Menu. P\u0159esto\u017ee se jedn\u00e1 o b\u011b\u017enou a pou\u017e\u00edvanou v\u011bc, dnes si uk\u00e1\u017eeme, jak si vytvo\u0159it dal\u0161\u00ed m\u00edsto v \u0161ablon\u011b, kam m\u016f\u017eeme um\u00edstit jak\u00e9koliv menu.<\/p>\n","protected":false},"author":1,"featured_media":344,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[401,544],"class_list":["post-9825","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-navody","tag-vlastni-menu","tag-wp_nav_menu"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/9825"}],"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=9825"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/9825\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/344"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=9825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=9825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=9825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}