{"id":9836,"date":"2013-05-17T19:15:10","date_gmt":"2013-05-17T19:15:10","guid":{"rendered":"http:\/\/musilda.cz\/?p=416"},"modified":"2013-05-17T19:15:10","modified_gmt":"2013-05-17T19:15:10","slug":"jak-upravit-zakladni-vzhled-komentaru-ve-wordpress","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-upravit-zakladni-vzhled-komentaru-ve-wordpress\/","title":{"rendered":"Jak upravit z\u00e1kladn\u00ed vzhled koment\u00e1\u0159\u016f ve WordPress"},"content":{"rendered":"<p>Jedn\u00edm ze z\u00e1kladn\u00edm post form\u00e1t\u016f ve WordPressu jsou koment\u00e1\u0159e. Pro ka\u017ed\u00e9ho blogera jsou nezastupiteln\u00fdm n\u00e1strojem pro komunikaci s komunitou \u010dten\u00e1\u0159\u016f. Proto\u017ee je v\u0161ak z\u00e1kladn\u00ed formul\u00e1\u0159 velmi jednoduch\u00fd a z\u00e1rove\u0148 nemus\u00ed jeho nastaven\u00ed vyhovovat ka\u017ed\u00e9mu, uk\u00e1\u017eeme si, jak jej jednodu\u0161e upravit k obrazu sv\u00e9mu.<!--more--><\/p>\n<p>Samotn\u00fd formul\u00e1\u0159 pro koment\u00e1\u0159e zobraz\u00edme v \u0161ablon\u011b pou\u017eit\u00edm funkce<\/p>\n<pre lang=\"php\">comment_form($args,$post_id);<\/pre>\n<p>V\u011bt\u0161inou v \u0161ablon\u00e1ch vid\u00edme jednoduch\u00fd z\u00e1pis comment_form(), ale pr\u00e1v\u011b vyu\u017eit\u00ed parametr\u016f funkce umo\u017e\u0148uje snadnou \u00fapravu z\u00e1kladn\u00edho formul\u00e1\u0159e. Vol\u00e1n\u00ed funkce bez parametr\u016f zobraz\u00ed formul\u00e1\u0159 takto:<\/p>\n<p><a href=\"http:\/\/musilda.cz\/wp-content\/uploads\/2013\/05\/formul\u00e1\u0159.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/musilda.cz\/wp-content\/uploads\/2013\/05\/formul\u00e1\u0159.png\" alt=\"\" title=\"formul\u00e1\u0159\" width=\"677\" height=\"659\" class=\"alignnone size-full wp-image-417\" \/><\/a><\/p>\n<p>Parametry, kter\u00e9 funkce obsahuje jsou tyto:<\/p>\n<ul>\n<li>fields<\/li>\n<li>comment_field<\/li>\n<li>must_log_in<\/li>\n<li>logged_in_as<\/li>\n<li>comment_notes_before<\/li>\n<li>comment_notes_after<\/li>\n<li>id_form<\/li>\n<li>id_submit<\/li>\n<li>title_reply<\/li>\n<li>title_reply_to<\/li>\n<li>cancel_reply_link<\/li>\n<li>label_submit<\/li>\n<\/ul>\n<p>V\u011bt\u0161inu z nich asi nebudete m\u00edt pot\u0159ebu m\u011bnit, ale n\u011bkdy se to m\u016f\u017ee hodit.<\/p>\n<h2>\u00daprava formul\u00e1\u0159e pomoc\u00ed parametr\u016f funkce<\/h2>\n<h3>Fields<\/h3>\n<p>Zobrazuje jednotliv\u00e1 pole formul\u00e1\u0159e, v z\u00e1kladn\u00edm nastaven\u00ed to je Name, Email, Website, p\u0159i\u010dem\u017e prvn\u00ed dv\u011b pole jsou povinn\u00e1. Pomoc\u00ed tohoto pole m\u016f\u017eete p\u0159id\u00e1vat, \u010di odeb\u00edrat jednotliv\u00e1 pole. Pokud nap\u0159\u00edklad chcete odebrat z formul\u00e1\u0159e polo\u017eku Website, pou\u017eijete n\u00e1sleduj\u00edc\u00ed k\u00f3d:<\/p>\n<pre lang=\"php\">\n$fields =  array(\n    'author' =&gt; '<p class=\"comment-form-author\">' . '<label for=\"author\">' . __( 'Name' ) .\n    '<\/label> ' . ( $req ? '<span class=\"required\">*<\/span>' : '' ) .\n    '<\/p>',\n    'email'  =&gt; '<p class=\"comment-form-email\"><label for=\"email\">' . __( 'Email' ) .\n    '<\/label> ' . ( $req ? '<span class=\"required\">*<\/span>' : '' ) .\n    '<\/p>',\n);\n\n$args = array(\n    'fields' =&gt;  $fields\n);\n\ncomment_form($args);\n<\/pre>\n<p>Prom\u011bnnou $req pou\u017eijete, pokud budete cht\u00edt p\u0159idat nov\u00e9 pole, kter\u00e9 bude povinn\u00e9. N\u00e1sleduj\u00edc\u00ed k\u00f3d p\u0159id\u00e1 do formul\u00e1\u0159e povinn\u00e9 pole s v\u011bkem:<\/p>\n<pre lang=\"php\">\n$fields =  array(\n    'author' =&gt; '<p class=\"comment-form-author\">' . '<label for=\"author\">' . __( 'Name' ) .\n    '<\/label> ' . ( $req ? '<span class=\"required\">*<\/span>' : '' ) .\n    '<\/p>',\n    'email'  =&gt; '<p class=\"comment-form-email\"><label for=\"email\">' . __( 'Email' ) .\n    '<\/label> ' . ( $req ? '<span class=\"required\">*<\/span>' : '' ) .\n    '<\/p>',\n    'age' =&gt; '<p class=\"comment-form-age\"><label for=\"age\">' . __( 'Age' ) .\n    '<\/label>' . ( $req ? '<span class=\"required\">*<\/span>' : '' ) .\n    '<\/p>'\n);\n\n$args = array(\n    'fields' =&gt;  apply_filters( 'comment_form_default_fields', $fields )\n);\n\ncomment_form($args);\n<\/pre>\n<h3>Comment_field<\/h3>\n<p>Zobrazen\u00ed textarea tagu ve formul\u00e1\u0159i. Jeho defaultn\u00ed hodnota je:<\/p>\n<pre lang=\"php\">\n<p class=\"comment-form-comment\"><label for=\"comment\">' . __( 'Comment' ) . '<\/label>\n<textarea id=\"comment\" name=\"comment\" cols=\"45\" rows=\"8\"><\/textarea><\/p>\n<\/pre>\n<p>Toto pole asi nebudete m\u00edt pot\u0159ebu m\u011bnit, ale pro p\u0159\u00edpadnou zm\u011bnu m\u016f\u017eete pou\u017e\u00edt n\u00e1sleduj\u00ed k\u00f3d:<\/p>\n<pre lang=\"php\">\n$args = array(\n    'comment_field' =&gt;  'html k\u00f3d pro va\u0161i textareu'\n);\n\ncomment_form($args);\n\n<\/pre>\n<h3>Must_log_in<\/h3>\n<p>Zobrazen\u00ed informace o nutnost\u00ed p\u0159ihl\u00e1\u0161en\u00ed, pro p\u0159id\u00e1n\u00ed koment\u00e1\u0159e. Z\u00e1kladn\u00ed hodnota je:<\/p>\n<pre lang=\"php\">\n<p class=\"must-log-in\">' .\nsprintf( __( 'You must be <a href=\"%s\">logged in<\/a> to post a comment.' ),\nwp_login_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '<\/p>\n<\/pre>\n<h3>Logged_in_as<\/h3>\n<p>Zobrazuje jm\u00e9no p\u0159ihl\u00e1\u0161en\u00e9ho u\u017eivatele a nahrazuje pole Name a Email. Z\u00e1kladn\u00ed hodnota je:<\/p>\n<pre lang=\"php\">\n<p class=\"logged-in-as\">' . sprintf( __( 'Logged in as <a href=\"%1$s\">%2$s<\/a>.\n<a href=\"%3$s\" title=\"Log out of this account\">Log out?<\/a>' ),\nadmin_url( 'profile.php' ), $user_identity,\nwp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '<\/p>\n<\/pre>\n<h3>Comment_notes_before<\/h3>\n<p>Zobrazuje text p\u0159ed koment\u00e1\u0159ov\u00fdm formul\u00e1\u0159em. Z\u00e1kladn\u00ed hodnota je:<\/p>\n<pre lang=\"php\">\n<p class=\"comment-notes\">' . __( 'Your email address will not be published.' ) .\n( $req ? $required_text : '' ) . '<\/p>\n<\/pre>\n<p>Pokud chcete text odstranit, sta\u010d\u00ed pou\u017e\u00edt n\u00e1sleduj\u00edc\u00ed k\u00f3d:<\/p>\n<pre lang=\"php\">\n$args = array(\n    'comment_notes_before' =&gt;  ''\n);\n\ncomment_form($args);\n<\/pre>\n<h3>Comment_notes_after<\/h3>\n<p>Zobrazuje text za textareou a p\u0159ed submit tla\u010d\u00edtkem. Z\u00e1kladn\u00ed hodnota je:<\/p>\n<pre lang=\"php\">\n<p class=\"form-allowed-tags\">' .\nsprintf( __( 'You may use these <abbr title=\"HyperText Markup Language\">HTML<\/abbr>\ntags and attributes: %s' ), ' <code>' . allowed_tags() . '<\/code>' ) . '<\/p>\n<\/pre>\n<p>Pokud chcete tento text odstranit, pou\u017eijte podobn\u00fd postup jako v p\u0159edchoz\u00edm p\u0159\u00edkladu:<\/p>\n<pre lang=\"php\">\n$args = array(\n    'comment_notes_after' =&gt;  ''\n);\n\ncomment_form($args);\n<\/pre>\n<h3>Dal\u0161\u00ed parametry funkce<\/h3>\n<p>Proto\u017ee n\u00e1sleduj\u00edc\u00ed parametry v\u011bt\u0161inou obsahuj\u00ed texty jednotliv\u00fdch prvk\u016f, shrnu je do jednoho odstavce.<\/p>\n<p>Id_form &#8211; hodnota id pro tag form, z\u00e1kladn\u00ed hodnota je &#8222;commentform&#8220;.<br \/>\nId_submit &#8211; hodnota id pro submit tla\u010ditko, z\u00e1kladn\u00ed hodnota je &#8222;submit&#8220;.<br \/>\nTitle_reply &#8211; titulek nad formul\u00e1\u0159em, z\u00e1kladn\u00ed hodnota je &#8222;Leave Reply&#8220;.<br \/>\nTitle_reply_to &#8211; titulek nad formul\u00e1\u0159em p\u0159i odpov\u011bdi, z\u00e1kladn\u00ed hodnota je &#8222;Leave Reply to %&#8220;.<br \/>\nCancel_reply_link &#8211; text odkazu pro vymaz\u00e1n\u00ed odpov\u011bdi, z\u00e1kladn\u00ed hodnota je &#8222;Cancel reply&#8220;.<br \/>\nLabel_submit &#8211; text tla\u010d\u00edtka pro odesl\u00e1n\u00ed koment\u00e1\u0159e, z\u00e1kladn\u00ed hodnota je &#8222;Post Comment&#8220;.<\/p>\n<p>Pou\u017eit\u00ed:<\/p>\n<pre lang=\"php\">\n$args = array(\n    'id_form' =&gt;  'id formul\u00e1\u0159e',\n    'id_submit' =&gt; 'id tla\u010ditka',\n    'title_reply' =&gt; 'P\u0159idej koment\u00e1\u0159',\n    'title_reply_top' =&gt; 'P\u0159idej koment\u00e1\u0159 k',\n    'cancel_reply_link' =&gt; 'Vyma\u017e odpov\u011b\u010f',\n    'label_submit' =&gt; 'Odeslat koment\u00e1\u0159'\n);\n\ncomment_form($args);\n<\/pre>\n<h3>P\u0159id\u00e1n\u00ed a odebr\u00e1n\u00ed pol\u00ed pomoc\u00ed filtru<\/h3>\n<p>V p\u0159edchoz\u00edch p\u0159\u00edkladech jsme upravovali formul\u00e1\u0159 pomoc\u00ed funkce comment_form a jej\u00edch parametr\u016f. Nyn\u00ed si uk\u00e1\u017eeme, jak vyu\u017e\u00edt filtr comment_form_default_fields. Jak pomoc\u00ed tohoto filtru odebrat pole z formul\u00e1\u0159e jsem ukazoval v tomto <a href=\"http:\/\/musilda.cz\/jak-odstranit-pole-pro-url-z-komentaroveho-formulare\/\" target=\"_blank\" rel=\"noopener\">\u010dl\u00e1nku<\/a>. Proto zde uvedu pouze postup jak p\u0159idat do formul\u00e1\u0159e dal\u0161\u00ed pole.<\/p>\n<p>Do souboru functions.php vlo\u017ete n\u00e1sleduj\u00edc\u00ed k\u00f3d:<\/p>\n<pre lang=\"php\">\nfunction add_comment_fields($fields) {\n\n$fields['age'] = '<p class=\"comment-form-age\"><label for=\"age\">' . __( 'Age' ) . '<\/label>' .\n   '<\/p>';\n    return $fields;\n\n}\nadd_filter('comment_form_default_fields','add_comment_fields');\n<\/pre>\n<p>T\u00edm do formul\u00e1\u0159e p\u0159id\u00e1te nepovinn\u00e9 pole V\u011bk. Stejn\u00fd v\u00fdsledek jsme dostali pomoc\u00ed pou\u017eit\u00ed fields ve funkci comment_form(). M\u00e1me tedy ve formul\u00e1\u0159i nov\u00e9 pole, ale je\u0161t\u011b jej mus\u00edme ulo\u017eit do datab\u00e1ze. Pou\u017eijeme comment meta a hooku &#8222;comment_post&#8220;. Do functions.php vlo\u017e\u00edme n\u00e1sleduj\u00edc\u00ed k\u00f3d:<\/p>\n<pre lang=\"php\">\nfunction add_comment_meta_values($comment_id) {\n\n    if(isset($_POST['age'])) {\n        $age = wp_filter_nohtml_kses($_POST['age']);\n        add_comment_meta($comment_id, 'age', $age, false);\n    }\n\n}\nadd_action ('comment_post', 'add_comment_meta_values', 1);\n<\/pre>\n<p>T\u00edm jsme ulo\u017eili v\u011bk do datab\u00e1ze jako comment meta a pokud jej budeme cht\u00edt zobrazit v \u0161ablon\u011b, pou\u017eijeme:<\/p>\n<pre lang=\"php\">\nget_comment_meta( $comment-&gt;comment_ID, 'age', true );\n<\/pre>\n<p>A jsme u konce. D\u00edky tomuto \u010dl\u00e1nku si m\u016f\u017eete upravit formul\u00e1\u0159 dle va\u0161ich po\u017eadavk\u016f. Pro dokonalou kontrolu nad zobrazov\u00e1n\u00edm koment\u00e1\u0159\u016f a formul\u00e1\u0159e je nutn\u00e9 pou\u017e\u00edt soubor comments.php, kter\u00fd, pokud je ve slo\u017ece aktu\u00e1ln\u00ed \u0161ablony, je automaticky na\u010dten a zobrazov\u00e1n\u00ed se \u0159\u00edd\u00ed pomoc\u00ed n\u011bj. Ale to bude sou\u010d\u00e1st n\u011bkter\u00e9ho z dal\u0161\u00edch \u010dl\u00e1nk\u016f.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Jedn\u00edm ze z\u00e1kladn\u00edm post form\u00e1t\u016f ve WordPressu jsou koment\u00e1\u0159e. Pro ka\u017ed\u00e9ho blogera jsou nezastupiteln\u00fdm n\u00e1strojem pro komunikaci s komunitou \u010dten\u00e1\u0159\u016f. Proto\u017ee je v\u0161ak z\u00e1kladn\u00ed formul\u00e1\u0159 velmi jednoduch\u00fd a z\u00e1rove\u0148 nemus\u00ed jeho nastaven\u00ed vyhovovat ka\u017ed\u00e9mu, uk\u00e1\u017eeme si, jak jej jednodu\u0161e upravit k obrazu sv\u00e9mu.<\/p>\n","protected":false},"author":1,"featured_media":8624,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","footnotes":""},"categories":[12],"tags":[220,269],"class_list":["post-9836","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-navody","tag-komentare","tag-odstraneni-pole-z-komentare"],"acf":[],"uagb_featured_image_src":{"full":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2013\/07\/wordpress-tutorial-musilda.png",1200,800,false],"thumbnail":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2013\/07\/wordpress-tutorial-musilda-150x150.png",150,150,true],"medium":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2013\/07\/wordpress-tutorial-musilda-300x200.png",300,200,true],"medium_large":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2013\/07\/wordpress-tutorial-musilda-768x512.png",640,427,true],"large":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2013\/07\/wordpress-tutorial-musilda-1024x683.png",640,427,true],"1536x1536":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2013\/07\/wordpress-tutorial-musilda.png",1200,800,false],"2048x2048":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2013\/07\/wordpress-tutorial-musilda.png",1200,800,false],"archive-list":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2013\/07\/wordpress-tutorial-musilda-400x265.png",400,265,true]},"uagb_author_info":{"display_name":"Affinite","author_link":"https:\/\/affinite.io\/cs\/author\/affinite\/"},"uagb_comment_info":12,"uagb_excerpt":"Jedn\u00edm ze z\u00e1kladn\u00edm post form\u00e1t\u016f ve WordPressu jsou koment\u00e1\u0159e. Pro ka\u017ed\u00e9ho blogera jsou nezastupiteln\u00fdm n\u00e1strojem pro komunikaci s komunitou \u010dten\u00e1\u0159\u016f. Proto\u017ee je v\u0161ak z\u00e1kladn\u00ed formul\u00e1\u0159 velmi jednoduch\u00fd a z\u00e1rove\u0148 nemus\u00ed jeho nastaven\u00ed vyhovovat ka\u017ed\u00e9mu, uk\u00e1\u017eeme si, jak jej jednodu\u0161e upravit k obrazu sv\u00e9mu.","_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/9836","targetHints":{"allow":["GET"]}}],"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=9836"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/9836\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/8624"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=9836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=9836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=9836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}