コアを弄るような阿呆な記事は参考にされない方が良いです。
【wordpress】コメントの入力欄を追加する/wp_list_comments表示カスタマイズ
http://satohmsys.info/wp_list_comments_custom/
おっと失礼しました
4、質問内容
・現在のWordPressのバージョンではどこに挿入すればいいのか
・又この館でできない場合、もっとも簡単な方法を教えてください
・追加も表示もできるプラグインがある場合教えてください
上から順に
最初のはコメントした通り。
真ん中は逆に質問、この館とは何ですか?簡単な方法はコメントの通り。
最後は分かりません。
書き込んだ人のタイプと記事の評価
評価は分かりますが、タイプはなんですか?
性別?血液型?
何であれ先に記したサイトの方法でどうにでもなると思います。
分からなければ訊いてください。
追記
タイプと評価の入力方法など分からないので例に挙げたサイトのコードをそのままです。
レイアウトを含め自身が想うように変更してください。
functions.phpにコメントフォームへの項目追加とデータベースに保存する設定のみ追加
// 1.コメント項目の追加
add_filter( 'comment_form_defaults','change_comment_form_input');
function change_comment_form_input($default) {
///////入力項目のカスタマイズ(名前のあとにつづく)
////タイトル
$default['fields']['email'] .= '<p class="comment-form-author commentForm-title">
<label for="commentTitle">'. __('タイトル') . '</label>
<input type="text" name="commentTitle" value="" placeholder="この商品についてひとこと" />
</p>';
////性別
$default['fields']['email'] .= '<p class="comment-form-author">
<label for="imMan"><input type="radio" name="sex" value="男性" id="imMan" />'. __('男性') . '</label>
<label for="imWoman"><input type="radio" name="sex" value="女性" id="imWoman" />'. __('女性') . '</label>
</p>';
////年齢層
$default['fields']['email'] .= '<p class="commentForm-age">
<label for="teen"><input type="radio" name="commenterAge" value="10代" id="teen" />'. __('10代') . '</label>
<label for="teen2"><input type="radio" name="commenterAge" value="20代" id="teen2" />'. __('20代') . '</label>
<label for="teen3"><input type="radio" name="commenterAge" value="30代" id="teen3" />'. __('30代') . '</label>
<label for="teen4"><input type="radio" name="commenterAge" value="40代" id="teen4" />'. __('40代') . '</label>
<label for="teen5"><input type="radio" name="commenterAge" value="50代" id="teen5" />'. __('50代') . '</label>
</p>';
return $default;
}
// 2 ちゃんとデータベースに入れる
///////データ更新
////性別
add_action( 'comment_post', 'save_comment_meta_data_sex' );
function save_comment_meta_data_sex( $comment_id ) {
$sex = $_POST['sex'];
return update_comment_meta( $comment_id, 'sex', $sex, true);
}
///タイトル
add_action( 'comment_post', 'save_comment_meta_data_title' );
function save_comment_meta_data_title( $comment_id ) {
$commentTitle = trim($_POST['commentTitle']);
return update_comment_meta( $comment_id, 'commentTitle', $commentTitle, true);
}
////年齢層
add_action( 'comment_post', 'save_comment_meta_data_age' );
function save_comment_meta_data_age( $comment_id ) {
$commenterAge = $_POST['commenterAge'];
return update_comment_meta( $comment_id, 'commenterAge', $commenterAge, true);
}
wp_commentmetaに保存された内容を出力
<h2>レビュー</h2>
<?php if(have_comments()): ?>
<ul>
<?php
$comments = get_comments(array(
'status' => 'approve',
'number' => 4 //四件表示
));
foreach ($comments as $comment) { ?>
<li>
<h3><?php the_title(); ?></h3>
<p><?php comment_author(); ?>
- 年齢:<?php echo get_comment_meta( $comment->comment_ID, 'commenterAge' ,true ); ?>
- 性別:<?php echo get_comment_meta( $comment->comment_ID, 'sex' ,true ); ?>
- タイトル:<?php echo get_comment_meta( $comment->comment_ID, 'commentTitle' ,true ); ?>
</p>
<p><?php echo mb_substr(get_comment_excerpt(), 0, 30); ?></p>
<a href="#">続きを読む</a>
</li>
<?php };?>
</ul>
<?php else : ?>
<p>まだ投稿されていません。</p>
<?php endif; ?>
</div>
<?php comment_form(); ?>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/10/04 12:53
退会済みユーザー
2017/10/04 23:52 編集