質問編集履歴

4

追加を追記

2017/07/11 03:16

投稿

cues
cues

スコア23

test CHANGED
File without changes
test CHANGED
@@ -317,3 +317,149 @@
317
317
 
318
318
 
319
319
  宜しくお願いいたします。
320
+
321
+
322
+
323
+ ###試したこと追記
324
+
325
+ 上記を下記のように修正したところ、
326
+
327
+ タームに春のみついているときは <li class="spring">
328
+
329
+ タームに夏のみついているときは、<li class="summer">を表示することができたのですが、
330
+
331
+ タームに春、夏 複数ついているときは <li class="spring">の条件式に当てはまってしまいます。
332
+
333
+
334
+
335
+ ```javascript
336
+
337
+
338
+
339
+ <ul>
340
+
341
+ <?php
342
+
343
+ $goodslist = get_posts( array(
344
+
345
+ 'post_type' => 'flyer', //特定のカスタム投稿タイプスラッグを指定
346
+
347
+ 'taxonomy' => 'flyer_cat', //特定のカスタムタクソノミースラッグを指定
348
+
349
+ 'term' => 'notice', //特定のカスタムタクソノミー内のタームスラッグを指定
350
+
351
+ 'posts_per_page' =>10//取得記事件数
352
+
353
+ ));
354
+
355
+ foreach( $goodslist as $post ):
356
+
357
+ setup_postdata( $post );
358
+
359
+ ?>
360
+
361
+ <?php if (is_object_in_term($post->ID, 'flyer_tag', 'spring')): ?>
362
+
363
+
364
+
365
+ <li class="spring">
366
+
367
+ <span class="samune">
368
+
369
+ </span>
370
+
371
+ <span><?php echo get_the_term_list($post->ID, 'flyer_cat'); ?></span>
372
+
373
+ <span><?php echo get_the_term_list($post->ID, 'flyer_tag'); ?></span>
374
+
375
+ <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
376
+
377
+
378
+
379
+ </li>
380
+
381
+
382
+
383
+ <?php elseif (is_object_in_term($post->ID, 'flyer_tag', 'summer')): ?>
384
+
385
+ <li class="summer">
386
+
387
+ <span class="samune">
388
+
389
+ </span>
390
+
391
+ <span><?php echo get_the_term_list($post->ID, 'flyer_cat'); ?></span>
392
+
393
+ <span><?php echo get_the_term_list($post->ID, 'flyer_tag'); ?></span>
394
+
395
+
396
+
397
+ <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
398
+
399
+
400
+
401
+ </li>
402
+
403
+
404
+
405
+
406
+
407
+ <?php elseif (is_object_in_term($post->ID, 'flyer_tag',array('spring','summer'))): ?>
408
+
409
+
410
+
411
+ <li class="spring summer">
412
+
413
+ <span class="samune">
414
+
415
+ </span>
416
+
417
+ <span><?php echo get_the_term_list($post->ID, 'flyer_cat'); ?></span>
418
+
419
+ <span><?php echo get_the_term_list($post->ID, 'flyer_tag'); ?></span>
420
+
421
+
422
+
423
+
424
+
425
+
426
+
427
+ <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
428
+
429
+
430
+
431
+ </li>
432
+
433
+ <?php else : ?>
434
+
435
+ 見つかりません。
436
+
437
+
438
+
439
+ <?php endif; ?>
440
+
441
+
442
+
443
+ <?php wp_reset_postdata(); wp_reset_query(); ?>
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+ <?php
452
+
453
+ endforeach;
454
+
455
+ wp_reset_postdata();
456
+
457
+ ?>
458
+
459
+ </ul>
460
+
461
+
462
+
463
+
464
+
465
+ ```

3

修正

2017/07/11 03:16

投稿

cues
cues

スコア23

test CHANGED
File without changes
test CHANGED
@@ -10,11 +10,11 @@
10
10
 
11
11
 
12
12
 
13
- 今回はカスタム投稿「flyer」を作成しました。
13
+ 今回はカスタム投稿「チラシ:flyer」を作成しました。
14
-
14
+
15
- ターム:お知らせ、イベント(flyer_cat)
15
+ ターム:お知らせ:notice、イベント:event(flyer_cat)
16
-
16
+
17
- 春、夏(flyer_tag)
17
+ :spring、夏:summer(flyer_tag)
18
18
 
19
19
 
20
20
 

2

修正

2017/07/11 02:25

投稿

cues
cues

スコア23

test CHANGED
File without changes
test CHANGED
@@ -20,9 +20,9 @@
20
20
 
21
21
  もっと良いやり方があるのであれば、ご教授いただければ幸いですが、
22
22
 
23
- JQでクラスをつけることで、チェックボックス絞込みができるものを見つけたので、
23
+ JQでclassをつけることで、チェックボックス絞込みができるものを見つけたので、
24
-
24
+
25
- その方法で春のタームが表示されるときは、liにのクラスがついて表示されるような流れで考えています。
25
+ その方法で春のタームが表示されるときは、liにspringのクラスがついて表示されるような流れで考えています。
26
26
 
27
27
 
28
28
 
@@ -32,7 +32,11 @@
32
32
 
33
33
  最後の <li class="spring summer">しか表示されません。
34
34
 
35
-
35
+ もし、タームに春がついているときは<li class="spring">を表示、
36
+
37
+ タームに夏がついているときは、<li class="summer">を表示、
38
+
39
+ タームに春、夏がついているときは <li class="spring summer">を表示する形にしたいです。
36
40
 
37
41
 
38
42
 

1

phpの方に絞って記入

2017/07/11 02:24

投稿

cues
cues

スコア23

test CHANGED
@@ -1 +1 @@
1
- グをチェックボックスで絞込みしたい
1
+ [WP] ームごとに表示したいです
test CHANGED
@@ -28,410 +28,288 @@
28
28
 
29
29
  ###発生している問題・エラーメッセージ
30
30
 
31
+ PHPのif条件がうまくいっていないのか、
32
+
31
- <li class="spring summer">の結果しか表示されません。
33
+ 最後の <li class="spring summer">しか表示されません。
32
-
34
+
35
+
36
+
37
+
38
+
33
- ```javascript
39
+ ```php
34
-
40
+
41
+
42
+
43
+
44
+
35
- <script>
45
+ <!-- 絞込み要素選択ここから -->
36
-
37
- $(function (){
46
+
38
-
39
- var $chkbxFilter_all = $('#all');
40
-
41
-
42
-
43
- //絞り込まないボタンをクリック時にチェックボックスをオフにする
44
-
45
- $chkbxFilter_all.click(function() {
47
+ <div id="select">
46
-
47
- $(".sort").prop('checked',false);
48
-
49
- $chkbxFilter_all.prop('checked',true);
50
-
51
- });
52
48
 
53
49
 
54
50
 
55
- //チェックックスがクリックされた時の動作
56
-
57
- $("#select label input").click(function() {
58
-
59
-
60
-
61
- $(this).parent().toggleClass("selected");
62
-
63
-
64
-
65
- $.each($chkbxFilter_tags, function() {
66
-
67
- if($('#' + this).is(':checked')) {
68
-
69
- $("#result " + $chkbxFilter_blocks + ":not(." + this + ")").addClass('hidden-not-' + this);
70
-
71
- $chkbxFilter_all.prop('checked',false).parent().removeClass("selected");
72
-
73
- }
74
-
75
- else if($('#' + this).not(':checked')) {
76
-
77
- $("#result " + $chkbxFilter_blocks + ":not(." + this + ")").removeClass('hidden-not-' + this);
78
-
79
- }
80
-
81
- });
82
-
83
-
84
-
85
- //チェックボックスが1つも選択されていない場合に、絞り込まないボタンにclass="selected"をつける
86
-
87
- if ($('.sort:checked').length == 0 ){
88
-
89
- $chkbxFilter_all.prop('checked',true).parent().addClass("selected");
90
-
91
- $(".sort").parent().removeClass("selected");
92
-
93
- };
94
-
95
- });
96
-
97
- });
98
-
99
- </script>
100
-
101
-
51
+ <!-- 絞り込まない(全表示)タン -->
52
+
53
+ <label class="selected"><input type="radio" id="all" checked="checked">絞り込まない</label>
54
+
55
+
56
+
57
+ <!-- 絞込みに使うタグをidとして指定します -->
58
+
59
+ <label><input type="checkbox" id="spring" class="sort">春</label>
60
+
61
+ <label><input type="checkbox" id="summer" class="sort">夏</label>
62
+
63
+
64
+
65
+ </div>
66
+
67
+ <!-- 絞込み要素選択ここまで -->
68
+
69
+
70
+
71
+
72
+
73
+ <!-- 絞込まれる要素ここから -->
74
+
75
+ <div id="result">
76
+
77
+
78
+
79
+ <!-- 絞込みに使うタグをclassとして指定します -->
80
+
81
+
82
+
83
+ <ul>
84
+
85
+ <?php
86
+
87
+ $goodslist = get_posts( array(
88
+
89
+ 'post_type' => 'flyer', //特定のカスタム投稿タイプスラッグを指定
90
+
91
+ 'taxonomy' => 'flyer_cat', //特定のカスタムタクソノミースラッグを指定
92
+
93
+ 'term' => 'event', //特定のカスタムタクソノミー内のタームスラッグを指定
94
+
95
+ 'posts_per_page' =>10//取得記事件数
96
+
97
+ ));
98
+
99
+ foreach( $goodslist as $post ):
100
+
101
+ setup_postdata( $post );
102
+
103
+ ?>
104
+
105
+ <?php if (have_posts()): ?>
106
+
107
+ <?php while(have_posts()):the_post(); ?>
108
+
109
+ <?php $term = esc_html(get_post_type_object(get_post_type())->name); ?>
110
+
111
+ <?php if($term=='spring'): ?>
112
+
113
+ <li class="spring">
114
+
115
+ <span class="samune">
116
+
117
+ </span>
118
+
119
+ <span><?php echo get_the_term_list($post->ID, 'flyer_cat'); ?></span>
120
+
121
+
122
+
123
+
124
+
125
+ <?php
126
+
127
+ if ($terms = get_the_terms($post->ID, 'flyer_tag')) {
128
+
129
+ foreach ( $terms as $term ) {
130
+
131
+ $term_slug = $term -> slug;
132
+
133
+ echo ('<span class="') ;
134
+
135
+ echo esc_html($term_slug) ;
136
+
137
+ echo ('">') ;
138
+
139
+ echo esc_html($term->name) ;
140
+
141
+ echo ('</span>') ;
142
+
143
+ }
144
+
145
+ }
146
+
147
+ ?>
148
+
149
+
150
+
151
+
152
+
153
+ <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
154
+
155
+
156
+
157
+ </li>
158
+
159
+
160
+
161
+ <?php elseif($term=='summer') : ?>
162
+
163
+ <li class="summer">
164
+
165
+ <span class="samune">
166
+
167
+ </span>
168
+
169
+ <span><?php echo get_the_term_list($post->ID, 'flyer_cat'); ?></span>
170
+
171
+
172
+
173
+
174
+
175
+ <?php
176
+
177
+ if ($terms = get_the_terms($post->ID, 'flyer_tag')) {
178
+
179
+ foreach ( $terms as $term ) {
180
+
181
+ $term_slug = $term -> slug;
182
+
183
+ echo ('<span class="') ;
184
+
185
+ echo esc_html($term_slug) ;
186
+
187
+ echo ('">') ;
188
+
189
+ echo esc_html($term->name) ;
190
+
191
+ echo ('</span>') ;
192
+
193
+ }
194
+
195
+ }
196
+
197
+ ?>
198
+
199
+
200
+
201
+
202
+
203
+ <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
204
+
205
+
206
+
207
+ </li>
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+ <?php else : ?>
218
+
219
+ <li class="spring summer">
220
+
221
+ <span class="samune">
222
+
223
+ </span>
224
+
225
+ <span><?php echo get_the_term_list($post->ID, 'flyer_cat'); ?></span>
226
+
227
+
228
+
229
+
230
+
231
+ <?php
232
+
233
+ if ($terms = get_the_terms($post->ID, 'flyer_tag')) {
234
+
235
+ foreach ( $terms as $term ) {
236
+
237
+ $term_slug = $term -> slug;
238
+
239
+ echo ('<span class="') ;
240
+
241
+ echo esc_html($term_slug) ;
242
+
243
+ echo ('">') ;
244
+
245
+ echo esc_html($term->name) ;
246
+
247
+ echo ('</span>') ;
248
+
249
+ }
250
+
251
+ }
252
+
253
+ ?>
254
+
255
+
256
+
257
+
258
+
259
+ <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
260
+
261
+
262
+
263
+ </li>
264
+
265
+ <?php endif; ?>
266
+
267
+ <?php endwhile; ?>
268
+
269
+
270
+
271
+
272
+
273
+ <?php else : ?>
274
+
275
+ <p>ただいま準備中です。しばらくお待ちください。</p>
276
+
277
+ <?php endif; ?>
278
+
279
+
280
+
281
+ <?php wp_reset_postdata(); wp_reset_query(); ?>
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+ <?php
290
+
291
+ endforeach;
292
+
293
+ wp_reset_postdata();
294
+
295
+ ?>
296
+
297
+ </ul>
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+ </div>
308
+
309
+ <!-- 絞込まれる要素ここまで -->
102
310
 
103
311
  ```
104
312
 
105
- ```css
106
-
107
- <style>
108
-
109
- /* ---------- 必須CSS ここから ------------ */
110
-
111
-
112
-
113
- #result [class*="hidden-"] {display: none;}
114
-
115
-
116
-
117
- /* ---------- 必須CSS ここまで ------------ */
118
-
119
-
120
-
121
-
122
-
123
- /* ここから下は見た目の調整 */
124
-
125
- #select {margin-bottom: 1em;}
126
-
127
- #result section{border: 1px solid #888; padding: 5px;}
128
-
129
- #result section p{margin: 0px;}
130
-
131
-
132
-
133
- #select label.selected {background-color: #fcc;} /* 選択中のラベルのスタイルを変更 */
134
-
135
-
136
-
137
- </style>
138
-
139
- ```
140
-
141
-
142
-
143
- ```php
144
-
145
- <!-- JS設定ここから -->
146
-
147
- <script>
148
-
149
- // 絞り込みに使うタグ(class)を記述してください。数の上限下限はありません。
150
-
151
- var $chkbxFilter_tags =['spring','summer'];
152
-
153
-
154
-
155
- // 絞り込み対象の要素のHTMLタグを指定してください。(div、section、tr など)
156
-
157
- var $chkbxFilter_blocks = ['li']
158
-
159
- </script>
160
-
161
- <!-- JS設定ここまで -->
162
-
163
-
164
-
165
-
166
-
167
- <!-- 絞込み要素選択ここから -->
168
-
169
- <div id="select">
170
-
171
-
172
-
173
- <!-- 絞り込まない(全表示)ボタン -->
174
-
175
- <label class="selected"><input type="radio" id="all" checked="checked">絞り込まない</label>
176
-
177
-
178
-
179
- <!-- 絞込みに使うタグをidとして指定します -->
180
-
181
- <label><input type="checkbox" id="spring" class="sort">春</label>
182
-
183
- <label><input type="checkbox" id="summer" class="sort">夏</label>
184
-
185
-
186
-
187
- </div>
188
-
189
- <!-- 絞込み要素選択ここまで -->
190
-
191
-
192
-
193
-
194
-
195
- <!-- 絞込まれる要素ここから -->
196
-
197
- <div id="result">
198
-
199
-
200
-
201
- <!-- 絞込みに使うタグをclassとして指定します -->
202
-
203
-
204
-
205
- <ul>
206
-
207
- <?php
208
-
209
- $goodslist = get_posts( array(
210
-
211
- 'post_type' => 'flyer', //特定のカスタム投稿タイプスラッグを指定
212
-
213
- 'taxonomy' => 'flyer_cat', //特定のカスタムタクソノミースラッグを指定
214
-
215
- 'term' => 'event', //特定のカスタムタクソノミー内のタームスラッグを指定
216
-
217
- 'posts_per_page' =>10//取得記事件数
218
-
219
- ));
220
-
221
- foreach( $goodslist as $post ):
222
-
223
- setup_postdata( $post );
224
-
225
- ?>
226
-
227
- <?php if (have_posts()): ?>
228
-
229
- <?php while(have_posts()):the_post(); ?>
230
-
231
- <?php $term = esc_html(get_post_type_object(get_post_type())->name); ?>
232
-
233
- <?php if($term=='spring'): ?>
234
-
235
- <li class="spring">
236
-
237
- <span class="samune">
238
-
239
- </span>
240
-
241
- <span><?php echo get_the_term_list($post->ID, 'flyer_cat'); ?></span>
242
-
243
-
244
-
245
-
246
-
247
- <?php
248
-
249
- if ($terms = get_the_terms($post->ID, 'flyer_tag')) {
250
-
251
- foreach ( $terms as $term ) {
252
-
253
- $term_slug = $term -> slug;
254
-
255
- echo ('<span class="') ;
256
-
257
- echo esc_html($term_slug) ;
258
-
259
- echo ('">') ;
260
-
261
- echo esc_html($term->name) ;
262
-
263
- echo ('</span>') ;
264
-
265
- }
266
-
267
- }
268
-
269
- ?>
270
-
271
-
272
-
273
-
274
-
275
- <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
276
-
277
-
278
-
279
- </li>
280
-
281
-
282
-
283
- <?php elseif($term=='summer') : ?>
284
-
285
- <li class="summer">
286
-
287
- <span class="samune">
288
-
289
- </span>
290
-
291
- <span><?php echo get_the_term_list($post->ID, 'flyer_cat'); ?></span>
292
-
293
-
294
-
295
-
296
-
297
- <?php
298
-
299
- if ($terms = get_the_terms($post->ID, 'flyer_tag')) {
300
-
301
- foreach ( $terms as $term ) {
302
-
303
- $term_slug = $term -> slug;
304
-
305
- echo ('<span class="') ;
306
-
307
- echo esc_html($term_slug) ;
308
-
309
- echo ('">') ;
310
-
311
- echo esc_html($term->name) ;
312
-
313
- echo ('</span>') ;
314
-
315
- }
316
-
317
- }
318
-
319
- ?>
320
-
321
-
322
-
323
-
324
-
325
- <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
326
-
327
-
328
-
329
- </li>
330
-
331
-
332
-
333
-
334
-
335
-
336
-
337
-
338
-
339
- <?php else : ?>
340
-
341
- <li class="spring summer">
342
-
343
- <span class="samune">
344
-
345
- </span>
346
-
347
- <span><?php echo get_the_term_list($post->ID, 'flyer_cat'); ?></span>
348
-
349
-
350
-
351
-
352
-
353
- <?php
354
-
355
- if ($terms = get_the_terms($post->ID, 'flyer_tag')) {
356
-
357
- foreach ( $terms as $term ) {
358
-
359
- $term_slug = $term -> slug;
360
-
361
- echo ('<span class="') ;
362
-
363
- echo esc_html($term_slug) ;
364
-
365
- echo ('">') ;
366
-
367
- echo esc_html($term->name) ;
368
-
369
- echo ('</span>') ;
370
-
371
- }
372
-
373
- }
374
-
375
- ?>
376
-
377
-
378
-
379
-
380
-
381
- <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
382
-
383
-
384
-
385
- </li>
386
-
387
- <?php endif; ?>
388
-
389
- <?php endwhile; ?>
390
-
391
-
392
-
393
-
394
-
395
- <?php else : ?>
396
-
397
- <p>ただいま準備中です。しばらくお待ちください。</p>
398
-
399
- <?php endif; ?>
400
-
401
-
402
-
403
- <?php wp_reset_postdata(); wp_reset_query(); ?>
404
-
405
-
406
-
407
-
408
-
409
-
410
-
411
- <?php
412
-
413
- endforeach;
414
-
415
- wp_reset_postdata();
416
-
417
- ?>
418
-
419
- </ul>
420
-
421
-
422
-
423
-
424
-
425
-
426
-
427
-
428
-
429
- </div>
430
-
431
- <!-- 絞込まれる要素ここまで -->
432
-
433
- ```
434
-
435
313
 
436
314
 
437
315
  宜しくお願いいたします。