2016-10-28 15 views
0

私は標準Wordpressのコメントフォームを使用していますが、私はそうのように、フォームに追加のフィールドとしてのラジオボタンを追加したいと思います:追加&店舗余分なフィールド - Wordpressのコメント

enter image description here

マイPHPへ追加情報(フロントエンドで)次のように標準的な形式があるが、私は追加するには最適なルートを知らない、店舗やショーを生成:

<?php 
$fields = array(
'author' => 
'<p class="comment-form-author"><label for="author">' . __('Name', 'domainreference') . '</label> ' . 
($req ? '<span class="required">*</span>' : '') . 
'<input id="author" name="author" placeholder="Enter your name" type="text" value="' . esc_attr($commenter['comment_author']) . '" size="30"' . $aria_req . ' /></p>', 

'email' => 
'<p class="comment-form-email"><label for="email">' . __('Email', 'domainreference') . '</label> ' . 
($req ? '<span class="required">*</span>' : '') . 
'<input id="email" name="email" placeholder="Enter your email address" type="text" value="' . esc_attr( $commenter['comment_author_email']) . '" size="30"' . $aria_req . ' /></p>', 

'comment_field' => 
    '<p class="comment-form-comment"><label for="comment">' . _x('Comment', 'noun') . 
'</label><textarea id="comment" placeholder="Enter your comment" name="comment" cols="45" rows="8" aria-required="true">' . 
'</textarea></p>' 
); 

$args = array(
    'id_form'   => 'commentform', 
    'class_form'  => 'comment-form', 
    'id_submit'   => 'submit', 
    'class_submit'  => 'submit btn', 
    'name_submit'  => 'submit', 
    'title_reply'  => __('Leave a Reply'), 
    'title_reply_to' => __('Leave a Reply to %s'), 
    'cancel_reply_link' => __('Cancel Reply'), 
    'label_submit'  => __('Post Comment'), 
    'format'   => 'xhtml', 

    'fields' => apply_filters('comment_form_default_fields', $fields) 

); 

comment_form($args); ?> 

答えて

0

コメントフォームに追加フィールドを挿入することが超簡単になり、高度なカスタムフィールド、私はすでに使用していたプラグインをオンにします。このプラグインを実行して、https://www.advancedcustomfields.com/resources/get-values-comment/

しかし、余計なCSSやJSファイルの束を追加します。

ACFはそれだけでこの方法と、出力コメントスレッド内のデータをに行うためのチュートリアルを作成したことがとても良いですフロントエンドにので、これらを削除するには、あなたのfunctions.phpにコードのこのビットを追加します。

// disable acf css on front-end acf forms 
add_action('wp_print_styles', 'my_deregister_styles', 100); 

function my_deregister_styles() { 
    wp_deregister_style('acf'); 
    wp_deregister_style('acf-field-group'); 
    wp_deregister_style('acf-global'); 
    wp_deregister_style('acf-input'); 
    wp_deregister_style('acf-datepicker'); 
} 
0

は&店舗余分なフィールドを追加 - Wordpressのコメントを

// Add the fields to comment form 
add_filter('comment_form_defaults', 'change_comment_form_defaults'); 
function change_comment_form_defaults($default) { 
    $commenter = wp_get_current_commenter(); 
    $default[ 'comment_field' ] .= '<p class="comment-form-author">' . 
             '<label for="vote-type">'. __('How are you like to vote?') . '</label> 
             <span class="required">*</span> 
             <input id="vote-type-yes" name="vote-type" size="30" type="radio" value="Yes" /> 
             <label for="vote-type-yes">Yes</label> 
             <input id="vote-type-no" name="vote-type" size="30" type="radio" value="No" /> 
             <label for="vote-type-no">No</label> 
             <input id="vote-type-maybe" name="vote-type" size="30" type="radio" value="No" /> 
             <label for="vote-type-maybe">May Be</label> 
            </p>'; 
      return $default; 
} 

// validations 
add_filter('pre_comment_on_post', 'verify_comment_meta_data'); 
function verify_comment_meta_data($commentdata) { 
     if (! isset($_POST['vote-type'])) 
     wp_die(__('Error: please fill the required field (How are you like to vote?).')); 
     return $commentdata; 
} 

// And save the comment meta 
add_action('comment_post', 'save_comment_meta_data'); 
function save_comment_meta_data($comment_id) { 
     add_comment_meta($comment_id, 'vote-type', $_POST[ 'vote-type' ]); 
} 


// Retrieve and display comment meta 
add_filter('get_comment_author_link', 'attach_vote_type_to_author'); 
function attach_vote_type_to_author($author) { 
     $vote_type = get_comment_meta(get_comment_ID(), 'vote-type', true); 
     if ($vote_type) 
      $author .= " ($vote_type)"; 
     return $author; 
} 
+0

をこれが正見えますが、どこ私の既存のコードに私はあなたのコードを配置しますか?私は自分のコードにペーストしましたが、うまくいきませんでした – egr103

関連する問題