teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

2017/10/04 23:52

投稿

退会済みユーザー
answer CHANGED
@@ -20,4 +20,93 @@
20
20
  性別?血液型?
21
21
 
22
22
  何であれ先に記したサイトの方法でどうにでもなると思います。
23
- 分からなければ訊いてください。
23
+ 分からなければ訊いてください。
24
+
25
+
26
+ **追記**
27
+ タイプと評価の入力方法など分からないので例に挙げたサイトのコードをそのままです。
28
+ レイアウトを含め自身が想うように変更してください。
29
+
30
+ functions.phpにコメントフォームへの項目追加とデータベースに保存する設定のみ追加
31
+ ```
32
+ // 1.コメント項目の追加
33
+ add_filter( 'comment_form_defaults','change_comment_form_input');
34
+ function change_comment_form_input($default) {
35
+ ///////入力項目のカスタマイズ(名前のあとにつづく)
36
+
37
+ ////タイトル
38
+ $default['fields']['email'] .= '<p class="comment-form-author commentForm-title">
39
+ <label for="commentTitle">'. __('タイトル') . '</label>
40
+ <input type="text" name="commentTitle" value="" placeholder="この商品についてひとこと" />
41
+ </p>';
42
+
43
+ ////性別
44
+ $default['fields']['email'] .= '<p class="comment-form-author">
45
+ <label for="imMan"><input type="radio" name="sex" value="男性" id="imMan" />'. __('男性') . '</label>
46
+ <label for="imWoman"><input type="radio" name="sex" value="女性" id="imWoman" />'. __('女性') . '</label>
47
+ </p>';
48
+
49
+ ////年齢層
50
+ $default['fields']['email'] .= '<p class="commentForm-age">
51
+ <label for="teen"><input type="radio" name="commenterAge" value="10代" id="teen" />'. __('10代') . '</label>
52
+ <label for="teen2"><input type="radio" name="commenterAge" value="20代" id="teen2" />'. __('20代') . '</label>
53
+ <label for="teen3"><input type="radio" name="commenterAge" value="30代" id="teen3" />'. __('30代') . '</label>
54
+ <label for="teen4"><input type="radio" name="commenterAge" value="40代" id="teen4" />'. __('40代') . '</label>
55
+ <label for="teen5"><input type="radio" name="commenterAge" value="50代" id="teen5" />'. __('50代') . '</label>
56
+ </p>';
57
+
58
+ return $default;
59
+ }
60
+ // 2 ちゃんとデータベースに入れる
61
+ ///////データ更新
62
+ ////性別
63
+ add_action( 'comment_post', 'save_comment_meta_data_sex' );
64
+ function save_comment_meta_data_sex( $comment_id ) {
65
+ $sex = $_POST['sex'];
66
+ return update_comment_meta( $comment_id, 'sex', $sex, true);
67
+ }
68
+ ///タイトル
69
+ add_action( 'comment_post', 'save_comment_meta_data_title' );
70
+ function save_comment_meta_data_title( $comment_id ) {
71
+ $commentTitle = trim($_POST['commentTitle']);
72
+ return update_comment_meta( $comment_id, 'commentTitle', $commentTitle, true);
73
+ }
74
+ ////年齢層
75
+ add_action( 'comment_post', 'save_comment_meta_data_age' );
76
+ function save_comment_meta_data_age( $comment_id ) {
77
+ $commenterAge = $_POST['commenterAge'];
78
+ return update_comment_meta( $comment_id, 'commenterAge', $commenterAge, true);
79
+ }
80
+ ```
81
+
82
+ wp_commentmetaに保存された内容を出力
83
+
84
+ ```
85
+ <h2>レビュー</h2>
86
+ <?php if(have_comments()): ?>
87
+ <ul>
88
+ <?php
89
+ $comments = get_comments(array(
90
+ 'status' => 'approve',
91
+ 'number' => 4 //四件表示
92
+ ));
93
+ foreach ($comments as $comment) { ?>
94
+ <li>
95
+ <h3><?php the_title(); ?></h3>
96
+ <p><?php comment_author(); ?>
97
+ - 年齢:<?php echo get_comment_meta( $comment->comment_ID, 'commenterAge' ,true ); ?>
98
+ - 性別:<?php echo get_comment_meta( $comment->comment_ID, 'sex' ,true ); ?>
99
+ - タイトル:<?php echo get_comment_meta( $comment->comment_ID, 'commentTitle' ,true ); ?>
100
+ </p>
101
+ <p><?php echo mb_substr(get_comment_excerpt(), 0, 30); ?></p>
102
+ <a href="#">続きを読む</a>
103
+ </li>
104
+ <?php };?>
105
+ </ul>
106
+ <?php else : ?>
107
+ <p>まだ投稿されていません。</p>
108
+ <?php endif; ?>
109
+ </div>
110
+
111
+ <?php comment_form(); ?>
112
+ ```

1

2017/10/04 23:52

投稿

退会済みユーザー
answer CHANGED
@@ -1,4 +1,23 @@
1
1
  コアを弄るような阿呆な記事は参考にされない方が良いです。
2
2
 
3
3
  【wordpress】コメントの入力欄を追加する/wp_list_comments表示カスタマイズ
4
- [http://satohmsys.info/wp_list_comments_custom/](http://satohmsys.info/wp_list_comments_custom/)
4
+ [http://satohmsys.info/wp_list_comments_custom/](http://satohmsys.info/wp_list_comments_custom/)
5
+
6
+ おっと失礼しました
7
+ > 4、質問内容
8
+ > ・現在のWordPressのバージョンではどこに挿入すればいいのか
9
+ > ・又この館でできない場合、もっとも簡単な方法を教えてください
10
+ > ・追加も表示もできるプラグインがある場合教えてください
11
+
12
+ 上から順に
13
+ 最初のはコメントした通り。
14
+ 真ん中は逆に質問、**この館**とは何ですか?簡単な方法はコメントの通り。
15
+ 最後は分かりません。
16
+
17
+ > 書き込んだ人のタイプと記事の評価
18
+
19
+ 評価は分かりますが、タイプはなんですか?
20
+ 性別?血液型?
21
+
22
+ 何であれ先に記したサイトの方法でどうにでもなると思います。
23
+ 分からなければ訊いてください。