質問編集履歴

1

コード全体の記載

2020/03/20 10:04

投稿

benkyosuruo
benkyosuruo

スコア16

test CHANGED
File without changes
test CHANGED
@@ -138,10 +138,74 @@
138
138
 
139
139
  ```
140
140
 
141
+ <div class="main__wrapper">
142
+
143
+ <main class="news__contents">
144
+
141
- }
145
+ <?php
146
+
147
+ $args = array(
148
+
149
+ 'post_type' => 'news',
150
+
151
+ // 'posts_per_page' => get_option('posts_per_page'),
152
+
153
+ 'posts_per_page' => 10,
154
+
155
+ ); ?>
156
+
157
+ <?php $my_posts = get_posts( $args ); ?>
158
+
159
+ <ul class="news-items">
160
+
161
+ <?php
162
+
163
+ global $post;
164
+
165
+ if($posts): foreach($my_posts as $post): setup_postdata($post);
166
+
167
+ $post_id = $post->ID;
168
+
169
+ $link = get_post_meta($post_id,'link',true);
142
170
 
143
171
  ?>
144
172
 
173
+ <?php if($link) : ?>
174
+
175
+ <li class="news-list">
176
+
177
+ <a class="news-list__link" href="<?php echo $link; ?>">
178
+
179
+ <div class="news-list__set">
180
+
181
+ <time class="news-list__time" datetime="2019-02-01"><?php the_time(__('Y年n月j日')) ?></time>
182
+
183
+
184
+
185
+ <?php
186
+
187
+ if ($terms = get_the_terms($post->ID, 'cat_news')) {
188
+
189
+ foreach ( $terms as $term ) {
190
+
191
+ $term_slug = $term -> slug;
192
+
193
+ echo ('<div class="news-list__label ') ;
194
+
195
+ echo esc_html($term_slug) ;
196
+
197
+ echo ('">') ;
198
+
199
+ echo esc_html($term->name) ;
200
+
201
+ echo ('</div>') ;
202
+
203
+ }
204
+
205
+ }
206
+
207
+ ?>
208
+
145
209
  </div>
146
210
 
147
211
  <p class="news-list__txt">
@@ -154,6 +218,52 @@
154
218
 
155
219
  </li>
156
220
 
221
+ <?php else : ?>
222
+
223
+ <li class="news-list">
224
+
225
+ <a class="news-list__link" href="<?php the_permalink() ?>">
226
+
227
+ <div class="news-list__set">
228
+
229
+ <time class="news-list__time" datetime="2019-02-01"><?php the_time(__('Y年n月j日')) ?></time>
230
+
231
+ <?php
232
+
233
+ if ($terms = get_the_terms($post->ID, 'cat_news')) {
234
+
235
+ foreach ( $terms as $term ) {
236
+
237
+ $term_slug = $term -> slug;
238
+
239
+ echo ('<div class="news-list__label ') ;
240
+
241
+ echo esc_html($term_slug) ;
242
+
243
+ echo ('">') ;
244
+
245
+ echo esc_html($term->name) ;
246
+
247
+ echo ('</div>') ;
248
+
249
+ }
250
+
251
+ }
252
+
253
+ ?>
254
+
255
+ </div>
256
+
257
+ <p class="news-list__txt">
258
+
259
+ <?php the_title(); ?>
260
+
261
+ </p>
262
+
263
+ </a>
264
+
265
+ </li>
266
+
157
267
  <?php endif; ?>
158
268
 
159
269
  <?php endforeach; endif;?>
@@ -174,42 +284,14 @@
174
284
 
175
285
  ?>
176
286
 
287
+
288
+
289
+
290
+
291
+
292
+
177
293
  </main>
178
294
 
179
-
180
-
181
- <aside class="sidebar__contents">
182
-
183
- <div class="sidebar-item">
184
-
185
- <p class="sidebar-item__ttl">新着記事</p>
186
-
187
-
188
-
189
- <?php
190
-
191
- $args = array(
192
-
193
- 'post_type' => 'news',
194
-
195
- // 'posts_per_page' => 5,
196
-
197
- 'post_status' => 'publish',
198
-
199
-
200
-
201
- ); ?>
202
-
203
- <?php $my_posts = get_posts( $args ); ?>
204
-
205
- <ul class="sidebar-item__menu">
206
-
207
- <?php
208
-
209
- global $post;
210
-
211
- if($posts): foreach($my_posts as $post): setup_postdata($post);
212
-
213
295
  ```
214
296
 
215
297