質問編集履歴

1

追加したコードの記述

2020/04/29 01:29

投稿

ral819
ral819

スコア20

test CHANGED
File without changes
test CHANGED
@@ -164,6 +164,144 @@
164
164
 
165
165
 
166
166
 
167
+ ```php
168
+
169
+ //追加したコード
170
+
171
+ <li class="page-footer__block footer-block">
172
+
173
+ <h4>Recent posts</h4>
174
+
175
+ <?php
176
+
177
+ $args = array(
178
+
179
+ 'post_type' => 'post',
180
+
181
+ 'posts_per_page' => 3,
182
+
183
+ );
184
+
185
+ $the_query = new WP_Query( $args );
186
+
187
+ if ( $the_query->have_posts() ) :
188
+
189
+ while ( $the_query->have_posts() ) : $the_query->the_post();
190
+
191
+ ?>
192
+
193
+ <!-- ループ内容 -->
194
+
195
+ <?php if(have_posts()):while(have_posts()): the_post(); ?>
196
+
197
+ <div class="footer-block__wrapper footer-wrapper">
198
+
199
+ <a href="<?php the_permalink(); ?>">
200
+
201
+ <p class="footer-wrapper__image">
202
+
203
+ <?php if(has_Post_thumbnail()): ?>
204
+
205
+ <?php the_post_thumbnail(('full')) ?>
206
+
207
+ <?php else:?>
208
+
209
+ <img src="https://placehold.jp/600x400.png" alt="">
210
+
211
+ <?php endif; ?>
212
+
213
+ </p>
214
+
215
+ </a>
216
+
217
+ <div class="footer-wrapper__texts">
218
+
219
+ <p class="date"><?php the_time('Y/m/d'); ?></p>
220
+
221
+ <a href="">
222
+
223
+ <h5><?php the_title(); ?></h5>
224
+
225
+ </a>
226
+
227
+ </div>
228
+
229
+ </div>
230
+
231
+ <?php endwhile; ?>
232
+
233
+ <?php endif; ?>
234
+
235
+ <?php
236
+
237
+ endwhile;
238
+
239
+ endif;
240
+
241
+ ?>
242
+
243
+ <?php wp_reset_postdata(); ?>
244
+
245
+
246
+
247
+ </li>
248
+
249
+
250
+
251
+ ```
252
+
253
+
254
+
255
+ ```php
256
+
257
+ //functions.php
258
+
259
+
260
+
261
+
262
+
263
+ //表示数制限
264
+
265
+
266
+
267
+ function my_pre_get_posts( $query ) {
268
+
269
+ if ( is_admin() || ! $query -> is_main_query() ) return;
270
+
271
+
272
+
273
+ if ( $query->is_home ) {
274
+
275
+ $query->set( 'posts_per_page', '6' );
276
+
277
+ $query->set( 'orderby', 'rand' );
278
+
279
+ }
280
+
281
+
282
+
283
+ if ( $query -> is_archive() ) {
284
+
285
+ $query -> set( 'posts_per_page', '5' );
286
+
287
+ }
288
+
289
+ }
290
+
291
+ add_action( 'pre_get_posts', 'my_pre_get_posts' );
292
+
293
+
294
+
295
+
296
+
297
+ ?>
298
+
299
+
300
+
301
+ ```
302
+
303
+
304
+
167
305
  ### 試したこと
168
306
 
169
307