{"id":2066,"date":"2014-10-10T20:50:32","date_gmt":"2014-10-10T20:50:32","guid":{"rendered":"http:\/\/musilda.cz\/?p=2066"},"modified":"2014-10-10T20:50:32","modified_gmt":"2014-10-10T20:50:32","slug":"jak-vytvorit-vlastni-sablonu-pro-wordpress-7-dil","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-vytvorit-vlastni-sablonu-pro-wordpress-7-dil\/","title":{"rendered":"Jak vytvo\u0159it vlastn\u00ed \u0161ablonu pro WordPress \u2013 7 d\u00edl"},"content":{"rendered":"\n

V minul\u00e9m d\u00edle jsme se dotkli souboru pro v\u00fdpis koment\u00e1\u0159\u016f a v dne\u0161n\u00edm si uk\u00e1\u017eeme, jak by m\u011bl skute\u010dn\u011b vypadat. Proto\u017ee nem\u00e1 smysl vym\u00fd\u0161let ji\u017e vymy\u0161len\u00e9, vezmeme soubor comments.php z WordPress \u0161ablony TwentyTwelve, na kter\u00e9 si v\u0161e vysv\u011btl\u00edme.<\/p>\n\n\n\n

V na\u0161em souboru m\u00e1me z minul\u00e9ho d\u00edlu comment list a comment_form(), to sma\u017eeme a na za\u010d\u00e1tek souboru vlo\u017e\u00edme<\/p>\n\n\n\n

<?php\nif ( post_password_required() )\n\treturn;\n?><\/code><\/pre>\n\n\n\n

Pokud se zobraz\u00ed p\u0159\u00edsp\u011bvek, kter\u00fd je chr\u00e1n\u011bn heslem a heslo nen\u00ed zad\u00e1no, nem\u00e1 smysl na\u010d\u00edtat soubor s koment\u00e1\u0159i.
Nyn\u00ed si vytvo\u0159\u00edme div, kter\u00fd obal\u00edme celou \u010d\u00e1st s koment\u00e1\u0159i, p\u0159id\u00e1me podm\u00ednku pro zobrazen\u00ed v\u00fdpisu, jen kdy\u017e n\u011bjak\u00e9 existuj\u00ed a nakonec zavol\u00e1me comment_form()<\/p>\n\n\n\n

<div id=\"comments\" class=\"comments-area\">\n<?php if ( have_comments() ) : ?>\n<?php\nendif;\ncomment_form();\n?>\n<\/div><\/code><\/pre>\n\n\n\n

V p\u0159\u00edpad\u011b, \u017ee chcete m\u00edt nad k\u00f3dem formul\u00e1\u0159e kontrolu, m\u016f\u017eete pou\u017e\u00edt tento k\u00f3d, m\u00edsto funkce comment_form()<\/p>\n\n\n\n

<form action=\"<?php echo get_option('siteurl'); ?>\/wp-comments-post.php\" method=\"post\" id=\"commentform\">\n\n<?php if ( is_user_logged_in() ) : ?>\n\n\t<p><?php printf(__('Logged in as %1$s. %2$sLog out &raquo;%3$s', 'theme'), '<a href=\"'.get_option('siteurl').'\/wp-admin\/profile.php\">'.$user_identity.'<\/a>', '<a href=\"'.(function_exists('wp_logout_url') ? wp_logout_url(get_permalink()) : get_option('siteurl').'\/wp-login.php?action=logout\" title=\"').'\" title=\"'.__('Log out of this account', 'theme').'\">', '<\/a>') ?><\/p>\n\n<?php else : ?>\n\n\t<p>\n            <label for=\"author\"><?php _e('Name', 'theme') ?> <span><?php if ($req) _e(\"*\", 'theme'); ?><\/span><\/label>\n            <input type=\"text\" name=\"author\" id=\"author\" value=\"<?php echo esc_attr($comment_author); ?>\" size=\"22\" tabindex=\"1\" \/>\n\t<\/p>\n\n\t<p>\n            <label for=\"email\"><?php _e('Email', 'theme') ?><span> <?php if ($req) _e(\"*\", 'theme'); ?><\/span><\/label>\n            <input type=\"text\" name=\"email\" id=\"email\" value=\"<?php echo esc_attr($comment_author_email); ?>\" size=\"22\" tabindex=\"2\" \/>\n\t<\/p>\n\n\t<p>\n            <label for=\"url\"><?php _e('Website', 'theme') ?><\/label>\n            <input type=\"text\" name=\"url\" id=\"url\" value=\"<?php echo esc_attr($comment_author_url); ?>\" size=\"22\" tabindex=\"3\" \/>\n\t<\/p>\n\n\t<?php endif; ?>\n\n\t<p>\n            <label for=\"comment\"><?php _e('Comment', 'theme') ?><\/label>\n            <textarea name=\"comment\" id=\"comment\" cols=\"58\" rows=\"10\" tabindex=\"4\"><\/textarea>\n        <\/p>\n\n\t<p>\n            \t<button class=\"com_button\" type=\"submit\" name=\"submit\">\n                    <?php _e('POST COMMENT', 'theme'); ?>\n                <\/button>\n\t    <?php comment_id_fields(); ?>\n\t<\/p>\n\t<?php do_action('comment_form', $post->ID); ?>\n<\/form><\/code><\/pre>\n\n\n\n

Jist\u011b jste si v\u0161imli, \u017ee na za\u010d\u00e1tku je podm\u00ednka s v\u00fdpisem jm\u00e9na u\u017eivatele, nebo odkazu pro p\u0159ihl\u00e1\u0161en\u00ed.
My se v\u0161ak budeme dr\u017eet funkce comment_form. Do podm\u00ednky if have comments p\u0159id\u00e1me titulek v\u00fdpisu koment\u00e1\u0159\u016f<\/p>\n\n\n\n

<h2 class=\"comments-title\">\n<?php\n\tprintf( _n( 'One thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', get_comments_number(), 'theme' ),\n\tnumber_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '<\/span>' );\n?>\n<\/h2><\/code><\/pre>\n\n\n\n

a pod titulek vyp\u00ed\u0161eme seznam koment\u00e1\u0159\u016f, kter\u00fd zn\u00e1me z minul\u00e9ho d\u00edlu<\/p>\n\n\n\n

<ol class=\"commentlist\">\n  <?php wp_list_comments(); ?>\n<\/ol><\/code><\/pre>\n\n\n\n

\u00dapln\u011b nakonec dopln\u00edme soubor o p\u0159\u00edpadn\u00e9 str\u00e1nkov\u00e1n\u00ed formul\u00e1\u0159\u016f a v\u00fdpis hl\u00e1\u0161ky, pokud jsou koment\u00e1\u0159e uzav\u0159eny<\/p>\n\n\n\n

<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>\n\t<nav id=\"comment-nav-below\" class=\"navigation\" role=\"navigation\">\n\t<h1 class=\"assistive-text section-heading\"><?php _e( 'Comment navigation', 'theme' ); ?><\/h1>\n\t\t<div class=\"nav-previous\"><?php previous_comments_link( __( '&larr; Older Comments', 'theme' ) ); ?><\/div>\n\t\t<div class=\"nav-next\"><?php next_comments_link( __( 'Newer Comments &rarr;', 'theme' ) ); ?><\/div>\n\t<\/nav>\n<?php endif; ?>\n\n<?php\nif ( ! comments_open() && get_comments_number() ) : ?>\n\t<p class=\"nocomments\"><?php _e( 'Comments are closed.' , 'theme' ); ?><\/p>\n<?php endif; ?><\/code><\/pre>\n\n\n\n

T\u00edm jsme ukon\u010dili soubor comments.php, kter\u00fd se n\u00e1m bude starat o v\u00fdpis koment\u00e1\u0159\u016f a formul\u00e1\u0159e pro jejich p\u0159id\u00e1v\u00e1n\u00ed. Cel\u00fd k\u00f3d vypad\u00e1 takto:<\/p>\n\n\n\n

<?php\nif ( post_password_required() )\n\treturn;\n?>\n<div id=\"comments\" class=\"comments-area\">\n<?php if ( have_comments() ) : ?>\n<h2 class=\"comments-title\">\n<?php\n\tprintf( _n( 'One thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', get_comments_number(), 'theme' ),\n\tnumber_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '<\/span>' );\n?>\n<\/h2>\n<ol class=\"commentlist\">\n  <?php wp_list_comments(); ?>\n<\/ol>\n\n<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>\n\t<nav id=\"comment-nav-below\" class=\"navigation\" role=\"navigation\">\n\t<h1 class=\"assistive-text section-heading\"><?php _e( 'Comment navigation', 'theme' ); ?><\/h1>\n\t\t<div class=\"nav-previous\"><?php previous_comments_link( __( '&larr; Older Comments', 'theme' ) ); ?><\/div>\n\t\t<div class=\"nav-next\"><?php next_comments_link( __( 'Newer Comments &rarr;', 'theme' ) ); ?><\/div>\n\t<\/nav>\n<?php endif; ?>\n\n<?php\nif ( ! comments_open() && get_comments_number() ) : ?>\n\t<p class=\"nocomments\"><?php _e( 'Comments are closed.' , 'theme' ); ?><\/p>\n<?php endif; ?>\n\n<?php\nendif;\ncomment_form();\n?>\n<\/div><\/code><\/pre>\n\n\n\n

To je pro dne\u0161ek v\u0161e, v p\u0159\u00ed\u0161t\u00edm d\u00edle si uk\u00e1\u017eeme, jak funguj\u00ed post form\u00e1ty a jak je zakomponovat do \u0161ablony.<\/p>\n\n\n\n

Seri\u00e1l: Jak vytvo\u0159it vlastn\u00ed \u0161ablonu pro WordPress<\/h2>\n\n\n\n