回答編集履歴
5
補足3の追加
answer
CHANGED
@@ -177,4 +177,200 @@
|
|
177
177
|
}
|
178
178
|
```
|
179
179
|
|
180
|
+
### 補足3
|
181
|
+
twentytwentyの以下の部分について、解説します。
|
182
|
+
```PHP
|
183
|
+
if ( have_posts() ) {
|
184
|
+
|
185
|
+
$i = 0;
|
186
|
+
|
187
|
+
while ( have_posts() ) {
|
188
|
+
$i++;
|
189
|
+
if ( $i > 1 ) {
|
190
|
+
echo '<hr class="post-separator styled-separator is-style-wide section-inner" aria-hidden="true" />';
|
191
|
+
}
|
192
|
+
the_post();
|
193
|
+
|
194
|
+
get_template_part( 'template-parts/content', get_post_type() );
|
195
|
+
|
196
|
+
}
|
197
|
+
}
|
198
|
+
```
|
199
|
+
まず全体が、
|
200
|
+
```PHP
|
201
|
+
if ( have_posts() ) {
|
202
|
+
|
203
|
+
|
204
|
+
}
|
205
|
+
```
|
206
|
+
で囲まれてますね。
|
207
|
+
|
208
|
+
これは、もし投稿があれば中身が実行されるということです。
|
209
|
+
|
210
|
+
次に、
|
211
|
+
```PHP
|
212
|
+
$i = 0;
|
213
|
+
```
|
214
|
+
ここでは、$iに0を入れています。この後で使います。
|
215
|
+
|
216
|
+
その下に、
|
217
|
+
```PHP
|
218
|
+
while ( have_posts() ) {
|
219
|
+
|
220
|
+
|
221
|
+
}
|
222
|
+
```
|
180
|
-
|
223
|
+
とあります。
|
224
|
+
|
225
|
+
これは、投稿がある間は中身をずっと繰り返すということです。
|
226
|
+
投稿が10件あれば、10回繰り返されます。
|
227
|
+
|
228
|
+
その直後の
|
229
|
+
```PHP
|
230
|
+
$i++;
|
231
|
+
```
|
232
|
+
は、自分自身に1を足すという意味です。
|
233
|
+
|
234
|
+
一番最初の $i を思い出してください。
|
235
|
+
0が入っていますね。
|
236
|
+
|
237
|
+
```PHP
|
238
|
+
$i++;
|
239
|
+
```
|
240
|
+
とすることで、 $i に 1 が入ります。
|
241
|
+
|
242
|
+
2周目は、1 + 1 = 2
|
243
|
+
3周目は、2 + 1 = 3
|
244
|
+
4周目は、3 + 1 = 4
|
245
|
+
|
246
|
+
が、$i に入ります。
|
247
|
+
|
248
|
+
つまり、1周目だけ、$i に 1が入っています。
|
249
|
+
|
250
|
+
その次に
|
251
|
+
```PHP
|
252
|
+
if ( $i > 1 ) {
|
253
|
+
echo '<hr class="post-separator styled-separator is-style-wide section-inner" aria-hidden="true" />';
|
254
|
+
}
|
255
|
+
```
|
256
|
+
とあります。
|
257
|
+
|
258
|
+
```PHP
|
259
|
+
if ( $i > 1 ) {
|
260
|
+
|
261
|
+
}
|
262
|
+
```
|
263
|
+
これは、もし$i が1よりも大きい時、中身を実行するという意味です。
|
264
|
+
|
265
|
+
中身は、こちらでしたね。
|
266
|
+
```PHP
|
267
|
+
echo '<hr class="post-separator styled-separator is-style-wide section-inner" aria-hidden="true" />';
|
268
|
+
```
|
269
|
+
これは、以下を表示するという意味です。
|
270
|
+
```HTML
|
271
|
+
<hr class="post-separator styled-separator is-style-wide section-inner" aria-hidden="true" />;
|
272
|
+
```
|
273
|
+
記事同士を区切っている線のことです。
|
274
|
+
|
275
|
+
```PHP
|
276
|
+
if ( $i > 1 ) {
|
277
|
+
echo '<hr class="post-separator styled-separator is-style-wide section-inner" aria-hidden="true" />';
|
278
|
+
}
|
279
|
+
```
|
280
|
+
ということは、$i が2以上の時、つまり、2つ目の投稿から
|
281
|
+
区切り線を表示するということです。
|
282
|
+
|
283
|
+
その次の
|
284
|
+
```PHP
|
285
|
+
the_post();
|
286
|
+
```
|
287
|
+
では、投稿のデータを取得しています。
|
288
|
+
|
289
|
+
ここでは、template-parts というフォルダの、content.php を読み込んでます。
|
290
|
+
```PHP
|
291
|
+
get_template_part( 'template-parts/content', get_post_type() );
|
292
|
+
```
|
293
|
+
|
294
|
+
長いですが、content.php は以下です。
|
295
|
+
```PHP
|
296
|
+
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
|
297
|
+
|
298
|
+
<?php
|
299
|
+
|
300
|
+
get_template_part( 'template-parts/entry-header' );
|
301
|
+
|
302
|
+
if ( ! is_search() ) {
|
303
|
+
get_template_part( 'template-parts/featured-image' );
|
304
|
+
}
|
305
|
+
|
306
|
+
?>
|
307
|
+
|
308
|
+
<div class="post-inner <?php echo is_page_template( 'templates/template-full-width.php' ) ? '' : 'thin'; ?> ">
|
309
|
+
|
310
|
+
<div class="entry-content">
|
311
|
+
|
312
|
+
<?php
|
313
|
+
if ( is_search() || ! is_singular() && 'summary' === get_theme_mod( 'blog_content', 'full' ) ) {
|
314
|
+
the_excerpt();
|
315
|
+
} else {
|
316
|
+
the_content( __( 'Continue reading', 'twentytwenty' ) );
|
317
|
+
}
|
318
|
+
?>
|
319
|
+
|
320
|
+
</div><!-- .entry-content -->
|
321
|
+
|
322
|
+
</div><!-- .post-inner -->
|
323
|
+
|
324
|
+
<div class="section-inner">
|
325
|
+
<?php
|
326
|
+
wp_link_pages(
|
327
|
+
array(
|
328
|
+
'before' => '<nav class="post-nav-links bg-light-background" aria-label="' . esc_attr__( 'Page', 'twentytwenty' ) . '"><span class="label">' . __( 'Pages:', 'twentytwenty' ) . '</span>',
|
329
|
+
'after' => '</nav>',
|
330
|
+
'link_before' => '<span class="page-number">',
|
331
|
+
'link_after' => '</span>',
|
332
|
+
)
|
333
|
+
);
|
334
|
+
|
335
|
+
edit_post_link();
|
336
|
+
|
337
|
+
// Single bottom post meta.
|
338
|
+
twentytwenty_the_post_meta( get_the_ID(), 'single-bottom' );
|
339
|
+
|
340
|
+
if ( post_type_supports( get_post_type( get_the_ID() ), 'author' ) && is_single() ) {
|
341
|
+
|
342
|
+
get_template_part( 'template-parts/entry-author-bio' );
|
343
|
+
|
344
|
+
}
|
345
|
+
?>
|
346
|
+
|
347
|
+
</div><!-- .section-inner -->
|
348
|
+
|
349
|
+
<?php
|
350
|
+
|
351
|
+
if ( is_single() ) {
|
352
|
+
|
353
|
+
get_template_part( 'template-parts/navigation' );
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
/**
|
358
|
+
* Output comments wrapper if it's a post, or if comments are open,
|
359
|
+
* or if there's a comment number – and check for password.
|
360
|
+
* */
|
361
|
+
if ( ( is_single() || is_page() ) && ( comments_open() || get_comments_number() ) && ! post_password_required() ) {
|
362
|
+
?>
|
363
|
+
|
364
|
+
<div class="comments-wrapper section-inner">
|
365
|
+
|
366
|
+
<?php comments_template(); ?>
|
367
|
+
|
368
|
+
</div><!-- .comments-wrapper -->
|
369
|
+
|
370
|
+
<?php
|
371
|
+
}
|
372
|
+
?>
|
373
|
+
|
374
|
+
</article><!-- .post -->
|
375
|
+
```
|
376
|
+
これが、一つ一つの投稿です。
|
4
補足2
answer
CHANGED
@@ -109,4 +109,72 @@
|
|
109
109
|
</body>
|
110
110
|
```
|
111
111
|
|
112
|
-
以上で高さが揃いました。
|
112
|
+
以上で一つ一つの投稿の高さが揃いました。
|
113
|
+
|
114
|
+
### 補足2
|
115
|
+
画像の高さを揃えるには、まず**img-wrap**で**<img>**を囲います。(計10箇所)
|
116
|
+
```HTML
|
117
|
+
<div class="img-wrap">
|
118
|
+
<img loading="lazy" class="aligncenter size-full wp-image-269" src="http://ictaga.com/members/okui/wp-content/uploads/2020/09/minori.jpg" alt="" width="768" height="576">
|
119
|
+
</div>
|
120
|
+
```
|
121
|
+
**img-wrap**に適応させるCSSはこちら
|
122
|
+
```CSS
|
123
|
+
.img-wrap {
|
124
|
+
height: 150px;
|
125
|
+
margin: 1rem 0;
|
126
|
+
overflow-y: hidden;
|
127
|
+
}
|
128
|
+
```
|
129
|
+
そうすると、タイトルが1行と2行の2パターン存在してしまい、画像の高さが少しだけ揃わなくなります。
|
130
|
+
そこで、タイトルが共通で持っている**entry-title**というクラスに以下のCSSを適応させます。
|
131
|
+
```CSS
|
132
|
+
.entry-title {
|
133
|
+
width: 100%;
|
134
|
+
display: -webkit-box;
|
135
|
+
-webkit-line-clamp: 1;
|
136
|
+
-webkit-box-orient: vertical;
|
137
|
+
overflow: hidden;
|
138
|
+
}
|
139
|
+
```
|
140
|
+
さらに、デバイスごとの横幅にも対応します。
|
141
|
+
以下の記述があることを確認し、
|
142
|
+
```HTML
|
143
|
+
<head>
|
144
|
+
|
145
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
146
|
+
|
147
|
+
</head>
|
148
|
+
```
|
149
|
+
デバイスの横幅が699pxまでの、投稿全体を覆う要素の幅を定義します。
|
150
|
+
```CSS
|
151
|
+
.article-wrap {
|
152
|
+
width: 256px;
|
153
|
+
}
|
154
|
+
```
|
155
|
+
700pxから
|
156
|
+
```CSS
|
157
|
+
@media screen and (min-width: 700px) {
|
158
|
+
.article-wrap {
|
159
|
+
width: 590px;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
```
|
163
|
+
1166pxから
|
164
|
+
```CSS
|
165
|
+
@media screen and (min-width: 1166px) {
|
166
|
+
.article-wrap {
|
167
|
+
width: 870px;
|
168
|
+
justify-content: flex-start;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
```
|
172
|
+
一つ一つの投稿は、以下のようにCSSを調整しました
|
173
|
+
```CSS
|
174
|
+
article {
|
175
|
+
min-width: 262px;
|
176
|
+
margin: 0 .5rem 3rem;
|
177
|
+
}
|
178
|
+
```
|
179
|
+
|
180
|
+
以上です!
|
3
文章の修正
answer
CHANGED
@@ -109,4 +109,4 @@
|
|
109
109
|
</body>
|
110
110
|
```
|
111
111
|
|
112
|
-
以上で高さが揃
|
112
|
+
以上で高さが揃いました。
|
2
補足
answer
CHANGED
@@ -66,14 +66,14 @@
|
|
66
66
|
|
67
67
|
1 jQueryの本体を準備する
|
68
68
|
|
69
|
-
jquery-3.5.1.min.jsを作成し、[このページ](https://jquery.com/download/)の以下の箇所をクリックした後のページから本体のコードをコピペします。
|
69
|
+
assets/jsに、jquery-3.5.1.min.jsを作成し、[このページ](https://jquery.com/download/)の以下の箇所をクリックした後のページから本体のコードをコピペします。
|
70
70
|

|
71
71
|
```jQuery
|
72
72
|
コピペしたコード
|
73
73
|
```
|
74
74
|
2 jquery.matchHeight.jsを準備する
|
75
75
|
|
76
|
-
jquery.matchHeight.jsを作成し、[このページ](https://raw.githubusercontent.com/liabru/jquery-match-height/master/jquery.matchHeight.js)からjquery.matchHeight.jsをコピペします。
|
76
|
+
assets/jsに、jquery.matchHeight.jsを作成し、[このページ](https://raw.githubusercontent.com/liabru/jquery-match-height/master/jquery.matchHeight.js)からjquery.matchHeight.jsをコピペします。
|
77
77
|
```jQuery
|
78
78
|
コピペしたコード
|
79
79
|
```
|
1
補足説明
answer
CHANGED
@@ -59,4 +59,54 @@
|
|
59
59
|
|
60
60
|
PHPが出力されたあとのHTMLを使用しました。
|
61
61
|
そのため、以下の箇所が計10回繰り返されています。
|
62
|
-

|
62
|
+

|
63
|
+
|
64
|
+
### 補足
|
65
|
+
[jquery.matchHeight](https://github.com/liabru/jquery-match-height)で、一つ一つのアイテムの高さを揃えました。
|
66
|
+
|
67
|
+
1 jQueryの本体を準備する
|
68
|
+
|
69
|
+
jquery-3.5.1.min.jsを作成し、[このページ](https://jquery.com/download/)の以下の箇所をクリックした後のページから本体のコードをコピペします。
|
70
|
+

|
71
|
+
```jQuery
|
72
|
+
コピペしたコード
|
73
|
+
```
|
74
|
+
2 jquery.matchHeight.jsを準備する
|
75
|
+
|
76
|
+
jquery.matchHeight.jsを作成し、[このページ](https://raw.githubusercontent.com/liabru/jquery-match-height/master/jquery.matchHeight.js)からjquery.matchHeight.jsをコピペします。
|
77
|
+
```jQuery
|
78
|
+
コピペしたコード
|
79
|
+
```
|
80
|
+
3 自分でスクリプトを用意する
|
81
|
+
|
82
|
+
例えば、script.jsを用意します。
|
83
|
+
```jQuery
|
84
|
+
(function ($) {
|
85
|
+
|
86
|
+
$('.item').matchHeight(
|
87
|
+
{
|
88
|
+
byRow: true,
|
89
|
+
property: 'height',
|
90
|
+
target: null,
|
91
|
+
remove: false
|
92
|
+
}
|
93
|
+
);
|
94
|
+
|
95
|
+
})(jQuery);
|
96
|
+
```
|
97
|
+
4 一つ一つの要素に同じクラスを付ける
|
98
|
+
|
99
|
+
**item**というクラスを以下の場所に付けます。(計10箇所)
|
100
|
+
```HTML
|
101
|
+
<article class="item post-268 post type-post status-publish format-standard has-post-thumbnail hentry category-kindergarten" id="post-268">
|
102
|
+
```
|
103
|
+
5 3つのファイルを読み込む
|
104
|
+
|
105
|
+
```HTML
|
106
|
+
<script src="assets/js/jquery-3.5.1.min.js"></script>
|
107
|
+
<script src="assets/js/jquery.matchHeight.js"></script>
|
108
|
+
<script src="assets/js/script.js"></script>
|
109
|
+
</body>
|
110
|
+
```
|
111
|
+
|
112
|
+
以上で高さが揃うかと思います。
|