回答編集履歴
2
test
CHANGED
@@ -43,3 +43,181 @@
|
|
43
43
|
何であれ先に記したサイトの方法でどうにでもなると思います。
|
44
44
|
|
45
45
|
分からなければ訊いてください。
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
**追記**
|
52
|
+
|
53
|
+
タイプと評価の入力方法など分からないので例に挙げたサイトのコードをそのままです。
|
54
|
+
|
55
|
+
レイアウトを含め自身が想うように変更してください。
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
functions.phpにコメントフォームへの項目追加とデータベースに保存する設定のみ追加
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
// 1.コメント項目の追加
|
64
|
+
|
65
|
+
add_filter( 'comment_form_defaults','change_comment_form_input');
|
66
|
+
|
67
|
+
function change_comment_form_input($default) {
|
68
|
+
|
69
|
+
///////入力項目のカスタマイズ(名前のあとにつづく)
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
////タイトル
|
74
|
+
|
75
|
+
$default['fields']['email'] .= '<p class="comment-form-author commentForm-title">
|
76
|
+
|
77
|
+
<label for="commentTitle">'. __('タイトル') . '</label>
|
78
|
+
|
79
|
+
<input type="text" name="commentTitle" value="" placeholder="この商品についてひとこと" />
|
80
|
+
|
81
|
+
</p>';
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
////性別
|
86
|
+
|
87
|
+
$default['fields']['email'] .= '<p class="comment-form-author">
|
88
|
+
|
89
|
+
<label for="imMan"><input type="radio" name="sex" value="男性" id="imMan" />'. __('男性') . '</label>
|
90
|
+
|
91
|
+
<label for="imWoman"><input type="radio" name="sex" value="女性" id="imWoman" />'. __('女性') . '</label>
|
92
|
+
|
93
|
+
</p>';
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
////年齢層
|
98
|
+
|
99
|
+
$default['fields']['email'] .= '<p class="commentForm-age">
|
100
|
+
|
101
|
+
<label for="teen"><input type="radio" name="commenterAge" value="10代" id="teen" />'. __('10代') . '</label>
|
102
|
+
|
103
|
+
<label for="teen2"><input type="radio" name="commenterAge" value="20代" id="teen2" />'. __('20代') . '</label>
|
104
|
+
|
105
|
+
<label for="teen3"><input type="radio" name="commenterAge" value="30代" id="teen3" />'. __('30代') . '</label>
|
106
|
+
|
107
|
+
<label for="teen4"><input type="radio" name="commenterAge" value="40代" id="teen4" />'. __('40代') . '</label>
|
108
|
+
|
109
|
+
<label for="teen5"><input type="radio" name="commenterAge" value="50代" id="teen5" />'. __('50代') . '</label>
|
110
|
+
|
111
|
+
</p>';
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
return $default;
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
// 2 ちゃんとデータベースに入れる
|
120
|
+
|
121
|
+
///////データ更新
|
122
|
+
|
123
|
+
////性別
|
124
|
+
|
125
|
+
add_action( 'comment_post', 'save_comment_meta_data_sex' );
|
126
|
+
|
127
|
+
function save_comment_meta_data_sex( $comment_id ) {
|
128
|
+
|
129
|
+
$sex = $_POST['sex'];
|
130
|
+
|
131
|
+
return update_comment_meta( $comment_id, 'sex', $sex, true);
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
///タイトル
|
136
|
+
|
137
|
+
add_action( 'comment_post', 'save_comment_meta_data_title' );
|
138
|
+
|
139
|
+
function save_comment_meta_data_title( $comment_id ) {
|
140
|
+
|
141
|
+
$commentTitle = trim($_POST['commentTitle']);
|
142
|
+
|
143
|
+
return update_comment_meta( $comment_id, 'commentTitle', $commentTitle, true);
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
////年齢層
|
148
|
+
|
149
|
+
add_action( 'comment_post', 'save_comment_meta_data_age' );
|
150
|
+
|
151
|
+
function save_comment_meta_data_age( $comment_id ) {
|
152
|
+
|
153
|
+
$commenterAge = $_POST['commenterAge'];
|
154
|
+
|
155
|
+
return update_comment_meta( $comment_id, 'commenterAge', $commenterAge, true);
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
```
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
wp_commentmetaに保存された内容を出力
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
<h2>レビュー</h2>
|
170
|
+
|
171
|
+
<?php if(have_comments()): ?>
|
172
|
+
|
173
|
+
<ul>
|
174
|
+
|
175
|
+
<?php
|
176
|
+
|
177
|
+
$comments = get_comments(array(
|
178
|
+
|
179
|
+
'status' => 'approve',
|
180
|
+
|
181
|
+
'number' => 4 //四件表示
|
182
|
+
|
183
|
+
));
|
184
|
+
|
185
|
+
foreach ($comments as $comment) { ?>
|
186
|
+
|
187
|
+
<li>
|
188
|
+
|
189
|
+
<h3><?php the_title(); ?></h3>
|
190
|
+
|
191
|
+
<p><?php comment_author(); ?>
|
192
|
+
|
193
|
+
- 年齢:<?php echo get_comment_meta( $comment->comment_ID, 'commenterAge' ,true ); ?>
|
194
|
+
|
195
|
+
- 性別:<?php echo get_comment_meta( $comment->comment_ID, 'sex' ,true ); ?>
|
196
|
+
|
197
|
+
- タイトル:<?php echo get_comment_meta( $comment->comment_ID, 'commentTitle' ,true ); ?>
|
198
|
+
|
199
|
+
</p>
|
200
|
+
|
201
|
+
<p><?php echo mb_substr(get_comment_excerpt(), 0, 30); ?></p>
|
202
|
+
|
203
|
+
<a href="#">続きを読む</a>
|
204
|
+
|
205
|
+
</li>
|
206
|
+
|
207
|
+
<?php };?>
|
208
|
+
|
209
|
+
</ul>
|
210
|
+
|
211
|
+
<?php else : ?>
|
212
|
+
|
213
|
+
<p>まだ投稿されていません。</p>
|
214
|
+
|
215
|
+
<?php endif; ?>
|
216
|
+
|
217
|
+
</div>
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
<?php comment_form(); ?>
|
222
|
+
|
223
|
+
```
|
1
test
CHANGED
@@ -5,3 +5,41 @@
|
|
5
5
|
【wordpress】コメントの入力欄を追加する/wp_list_comments表示カスタマイズ
|
6
6
|
|
7
7
|
[http://satohmsys.info/wp_list_comments_custom/](http://satohmsys.info/wp_list_comments_custom/)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
おっと失礼しました
|
12
|
+
|
13
|
+
> 4、質問内容
|
14
|
+
|
15
|
+
> ・現在のWordPressのバージョンではどこに挿入すればいいのか
|
16
|
+
|
17
|
+
> ・又この館でできない場合、もっとも簡単な方法を教えてください
|
18
|
+
|
19
|
+
> ・追加も表示もできるプラグインがある場合教えてください
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
上から順に
|
24
|
+
|
25
|
+
最初のはコメントした通り。
|
26
|
+
|
27
|
+
真ん中は逆に質問、**この館**とは何ですか?簡単な方法はコメントの通り。
|
28
|
+
|
29
|
+
最後は分かりません。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
> 書き込んだ人のタイプと記事の評価
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
評価は分かりますが、タイプはなんですか?
|
38
|
+
|
39
|
+
性別?血液型?
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
何であれ先に記したサイトの方法でどうにでもなると思います。
|
44
|
+
|
45
|
+
分からなければ訊いてください。
|