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

回答編集履歴

3

ソースコード不具合修正

2016/09/06 13:35

投稿

退会済みユーザー
answer CHANGED
@@ -1,5 +1,21 @@
1
1
  こんな感じとかですか。レイアウトにBootstrapを使っていいんですよね?
2
2
 
3
+ **訂正(2016/09/06 22:24)**
4
+ 投稿の全件数が3の倍数じゃないときに、div.show_boxが閉じられないバグを修正。
5
+ 直したので、一応載せときます。(新しいjQueryだと動かないと思うので、この回答修正は無視してくださいな)
6
+ ```Javascript
7
+ <script>
8
+ jQuery(function(){
9
+ jQuery('.show_box:not(.show_box:first-of-type)').css('display','none');
10
+ jQuery('.more').nextAll('.more').css('display','none');
11
+ jQuery('.more').on('click', function() {
12
+ jQuery(this).css('display','none');
13
+ jQuery(this).next('.show_box').slideDown('fast');
14
+ jQuery(this).nextAll('.more:first').css('display','block');
15
+ });
16
+ });
17
+ </script>
18
+ ```
3
19
  ```PHP
4
20
  <?php $counter = 0; ?>
5
21
  <?php $column = 3; ?>
@@ -8,8 +24,8 @@
8
24
  <?php if ( $my_query->have_posts() ) :while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
9
25
 
10
26
  <?php if( $counter % $column == 0 ) : ?>
11
- <!-- show_box -->
27
+ <!-- show_box -->
12
- <div class="show_box row">
28
+ <div class="show_box row">
13
29
  <?php endif; ?>
14
30
 
15
31
  <!-- boxed-white -->
@@ -35,17 +51,19 @@
35
51
  </div>
36
52
  <!-- /boxed-white -->
37
53
 
38
- <?php if( $counter % $column == $column-1 ) : ?>
54
+ <?php if( ($counter % $column == $column-1) || ($counter == ($my_query->post_count)-1) ) : ?>
39
- </div>
55
+ </div>
40
- <!-- /show_box -->
56
+ <!-- /show_box -->
57
+ <?php endif; ?>
41
58
 
59
+ <?php if( ($counter % $column == $column-1) && ($counter != ($my_query->post_count)-1) ) : ?>
42
- <!-- もっと見るボタン -->
60
+ <!-- もっと見るボタン -->
43
- <div class="more">
61
+ <div class="more">
44
- <div class="col-md-12">
62
+ <div class="col-md-12">
45
- <p class="box-more text-center">もっと見る</p>
63
+ <p class="box-more text-center">もっと見る</p>
46
- </div>
64
+ </div>
47
- </div>
65
+ </div>
48
- <!-- /もっと見るボタン -->
66
+ <!-- /もっと見るボタン -->
49
67
  <?php endif; ?>
50
68
 
51
69
  <?php $counter++; ?>

2

誤記訂正

2016/09/06 13:35

投稿

退会済みユーザー
answer CHANGED
@@ -4,7 +4,7 @@
4
4
  <?php $counter = 0; ?>
5
5
  <?php $column = 3; ?>
6
6
 
7
- <?php $my_query = new WP_Query( 'category_name=idw-g1' ); ?>
7
+ <?php $my_query = new WP_Query( 'category_name=event' ); ?>
8
8
  <?php if ( $my_query->have_posts() ) :while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
9
9
 
10
10
  <?php if( $counter % $column == 0 ) : ?>

1

ソース記述漏れ訂正

2016/09/06 07:15

投稿

退会済みユーザー
answer CHANGED
@@ -1,6 +1,7 @@
1
1
  こんな感じとかですか。レイアウトにBootstrapを使っていいんですよね?
2
2
 
3
+ ```PHP
3
- ```PHP<?php $counter = 0; ?>
4
+ <?php $counter = 0; ?>
4
5
  <?php $column = 3; ?>
5
6
 
6
7
  <?php $my_query = new WP_Query( 'category_name=idw-g1' ); ?>