質問編集履歴
5
微修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
wordpressのカスタム投稿タイプ(+カスタムタクソノミーも)をプラグインに頼らず利用したいと思い書き込みいたしました。
|
1
|
+
wordpressのカスタム投稿タイプ(+カスタムタクソノミーも)をプラグインに頼らず利用したいと思い書き込みいたしました。※テーマは _s(underscores)をカスタマイズして利用しています
|
2
|
-
|
3
|
-
※テーマは _s(underscores)をカスタマイズして利用しています
|
4
2
|
|
5
3
|
|
6
4
|
|
4
内容を更新・修正しました(文字数制限のため省略も)
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,14 +1,22 @@
|
|
1
|
-
wordpressのカスタム投稿タイプ(+カスタムタクソノミーも)をプラグインに頼らず利用したいと思い書き込みいたしました。
|
1
|
+
wordpressのカスタム投稿タイプ(+カスタムタクソノミーも)をプラグインに頼らず利用したいと思い書き込みいたしました。
|
2
|
+
|
2
|
-
|
3
|
+
※テーマは _s(underscores)をカスタマイズして利用しています
|
3
|
-
|
4
|
-
|
4
|
+
|
5
|
+
|
6
|
+
|
5
|
-
### 試したこと
|
7
|
+
### 試したこと ※追記あり
|
6
|
-
|
8
|
+
|
7
|
-
すでに解決済みの[こちらのページ](https://teratail.com/questions/33577)を参考にし、カスタム投稿一覧・記事ページで本文の表示はできました。しかしそのままでは日付が表示できなかったため、修正して日付は表示できました。
|
9
|
+
すでに解決済みの[こちらのページ](https://teratail.com/questions/33577)を参考にし、カスタム投稿一覧・記事ページで本文の表示はできました。しかしそのままでは日付が表示できなかったため、修正して日付は表示できるようになりました。
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
|
11
|
-
しかしどうしてもカスタムタクソノミーの情報(カテゴリーやタグ)の情報を出すことができず四苦八苦しております。
|
11
|
+
~~しかしどうしてもカスタムタクソノミーの情報(カテゴリーやタグ)の情報を出すことができず四苦八苦しております。~~
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
※その後いろいろ試行錯誤し、ターム(カテゴリーやタグ)の情報を出すことができるようになりました
|
16
|
+
|
17
|
+
しかし今度はタームをクリックした際に表示される一覧ページで、本文とターム情報が表示できず悩んでおります。
|
18
|
+
|
19
|
+
どうかお知恵をお貸しください・・・
|
12
20
|
|
13
21
|
|
14
22
|
|
@@ -16,7 +24,7 @@
|
|
16
24
|
|
17
25
|
//function.phpに書いたコード ※抜粋
|
18
26
|
|
19
|
-
|
27
|
+
|
20
28
|
|
21
29
|
add_action('init', 'blog_post_type');
|
22
30
|
|
@@ -42,12 +50,6 @@
|
|
42
50
|
|
43
51
|
'view_item' => 'ブログの説明を見る',
|
44
52
|
|
45
|
-
'search_items' => '検索する',
|
46
|
-
|
47
|
-
'not_found' => 'ブログが見つかりませんでした。',
|
48
|
-
|
49
|
-
'not_found_in_trash' => 'ゴミ箱内にブログが見つかりませんでした。'
|
50
|
-
|
51
53
|
),
|
52
54
|
|
53
55
|
'menu_position' => 5,
|
@@ -96,9 +98,9 @@
|
|
96
98
|
|
97
99
|
$labels = array(
|
98
100
|
|
99
|
-
'name' => 'カテゴリ',
|
101
|
+
'name' => 'カテゴリ',
|
100
|
-
|
102
|
+
|
101
|
-
'singular_name' => 'カテゴリ',
|
103
|
+
'singular_name' => 'カテゴリ',
|
102
104
|
|
103
105
|
'search_items' => 'カテゴリを検索',
|
104
106
|
|
@@ -116,7 +118,7 @@
|
|
116
118
|
|
117
119
|
'new_item_name' => '新規カテゴリ',
|
118
120
|
|
119
|
-
'menu_name' => 'カテゴリ'
|
121
|
+
'menu_name' => 'カテゴリ'
|
120
122
|
|
121
123
|
);
|
122
124
|
|
@@ -126,7 +128,7 @@
|
|
126
128
|
|
127
129
|
'labels' => $labels,
|
128
130
|
|
129
|
-
'rewrite' => array( 'slug' => 'blog_cat' )
|
131
|
+
'rewrite' => array( 'slug' => 'blog_category' )
|
130
132
|
|
131
133
|
);
|
132
134
|
|
@@ -138,9 +140,9 @@
|
|
138
140
|
|
139
141
|
$labels = array(
|
140
142
|
|
141
|
-
'name' => 'タグ',
|
143
|
+
'name' => 'タグ',
|
142
|
-
|
144
|
+
|
143
|
-
'singular_name' => 'タグ',
|
145
|
+
'singular_name' => 'タグ',
|
144
146
|
|
145
147
|
'search_items' => 'タグを検索',
|
146
148
|
|
@@ -166,7 +168,7 @@
|
|
166
168
|
|
167
169
|
'not_found' => 'アイテムは見つかりませんでした',
|
168
170
|
|
169
|
-
'menu_name' => 'タグ'
|
171
|
+
'menu_name' => 'タグ'
|
170
172
|
|
171
173
|
);
|
172
174
|
|
@@ -176,7 +178,7 @@
|
|
176
178
|
|
177
179
|
'labels' => $labels,
|
178
180
|
|
179
|
-
'update_count_callback' => '_update_post_term_count',
|
181
|
+
'update_count_callback' => '_update_post_term_count',
|
180
182
|
|
181
183
|
'rewrite' => array( 'slug' => 'blog_tag' )
|
182
184
|
|
@@ -194,406 +196,414 @@
|
|
194
196
|
|
195
197
|
|
196
198
|
|
199
|
+
```html
|
200
|
+
|
201
|
+
//一覧ページなどに書いたコード
|
202
|
+
|
203
|
+
<?php the_terms($post->ID,'blog'); ?>
|
204
|
+
|
205
|
+
```
|
206
|
+
|
207
|
+
|
208
|
+
|
197
209
|
```php
|
198
210
|
|
199
|
-
//
|
211
|
+
////archive.php ※抜粋 ※追記あり
|
212
|
+
|
200
|
-
|
213
|
+
<main>
|
214
|
+
|
215
|
+
<div id="box_main" class="col-sm-9 site-main" role="main">
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
<div id="entry_box">
|
220
|
+
|
221
|
+
<?php
|
222
|
+
|
223
|
+
<?php if ( have_posts() || is_tax() ) : ?><!-- ※ここを修正しました -->
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
<header class="page-header">
|
228
|
+
|
229
|
+
<?php
|
230
|
+
|
231
|
+
the_archive_title( '<h2 class="page-title">', '</h2>' );
|
232
|
+
|
233
|
+
the_archive_description( '<div class="taxonomy-description">', '</div>' );
|
234
|
+
|
235
|
+
?>
|
236
|
+
|
201
|
-
<
|
237
|
+
</header><!-- .page-header -->
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
<?php
|
242
|
+
|
243
|
+
/* Start the Loop */
|
244
|
+
|
245
|
+
while ( have_posts() ) : the_post();
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
/*
|
250
|
+
|
251
|
+
* Include the Post-Format-specific template for the content.
|
252
|
+
|
253
|
+
*/
|
254
|
+
|
255
|
+
get_template_part( 'template-parts/content', get_post_format() );
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
endwhile;
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
the_posts_navigation();
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
else :
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
get_template_part( 'template-parts/content', 'none' );
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
endif; ?>
|
276
|
+
|
277
|
+
</div>
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
</div>
|
282
|
+
|
283
|
+
</main>
|
284
|
+
|
285
|
+
|
202
286
|
|
203
287
|
```
|
204
288
|
|
205
289
|
|
206
290
|
|
207
|
-
```h
|
208
|
-
|
209
|
-
//
|
210
|
-
|
211
|
-
<
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
<div
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
</div>
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
</
|
282
|
-
|
283
|
-
|
291
|
+
```php
|
292
|
+
|
293
|
+
//content.php ※追記あり
|
294
|
+
|
295
|
+
<?php ?>
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
300
|
+
|
301
|
+
<div class="entry-header">
|
302
|
+
|
303
|
+
<?php
|
304
|
+
|
305
|
+
if ( is_single() ) :
|
306
|
+
|
307
|
+
the_title( '<h2 class="entry-title">', '</h2>' );
|
308
|
+
|
309
|
+
else :
|
310
|
+
|
311
|
+
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
|
312
|
+
|
313
|
+
endif;
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
//カスタム投稿を追加
|
318
|
+
|
319
|
+
wp_list_categories('title_li=&taxonomy=blog_category,blog_tag');
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
if ( 'post' === get_post_type() || 'blog' === get_post_type() ) : ?><!-- ※ここを修正しました -->
|
324
|
+
|
325
|
+
<div class="entry-meta">
|
326
|
+
|
327
|
+
<?php underscores_posted_on(); ?>
|
328
|
+
|
329
|
+
</div><!-- .entry-meta -->
|
330
|
+
|
331
|
+
<?php endif; ?>
|
332
|
+
|
333
|
+
</div><!-- .entry-header -->
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
<div class="entry-content clearfix">
|
340
|
+
|
341
|
+
<?php
|
342
|
+
|
343
|
+
the_content( sprintf(
|
344
|
+
|
345
|
+
/* translators: %s: Name of current post. */
|
346
|
+
|
347
|
+
wp_kses( __( '続きを読む', 'underscores' ), array( 'span' => array( 'class' => array() ) ) ),
|
348
|
+
|
349
|
+
the_title( '<span class="screen-reader-text">"', '"</span>', false )
|
350
|
+
|
351
|
+
) );
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
wp_link_pages( array(
|
356
|
+
|
357
|
+
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'underscores' ),
|
358
|
+
|
359
|
+
'after' => '</div>',
|
360
|
+
|
361
|
+
) );
|
362
|
+
|
363
|
+
?>
|
364
|
+
|
365
|
+
</div><!-- .entry-content -->
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
<div class="entry-footer">
|
370
|
+
|
371
|
+
<?php underscores_entry_footer(); ?>
|
372
|
+
|
373
|
+
</div><!-- .entry-footer -->
|
374
|
+
|
375
|
+
</article><!-- #post-## -->
|
284
376
|
|
285
377
|
```
|
286
378
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
/
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
379
|
+
### ファイルの構造
|
380
|
+
|
381
|
+
archive.php は content.php を読込み、content.php は template-tags.php を読込む構造になっているようです。
|
382
|
+
|
383
|
+
template-tags.php で共通表示される部分(本文やその他情報)を管理しているようです。
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
※色々試した結果「if ( 'blog' === get_post_type() ~」を追加して、タームの情報が表示できるようになりました
|
388
|
+
|
389
|
+
```php
|
390
|
+
|
391
|
+
//template-tags.php ※追記あり
|
392
|
+
|
393
|
+
<?php
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
if ( ! function_exists( 'underscores_posted_on' ) ) :
|
398
|
+
|
399
|
+
/**
|
400
|
+
|
401
|
+
* Prints HTML with meta information for the current post-date/time and author.
|
402
|
+
|
403
|
+
*/
|
404
|
+
|
405
|
+
function underscores_posted_on() {
|
406
|
+
|
407
|
+
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
|
408
|
+
|
409
|
+
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
|
410
|
+
|
411
|
+
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
|
412
|
+
|
413
|
+
}
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
$time_string = sprintf( $time_string,
|
418
|
+
|
419
|
+
esc_attr( get_the_date( 'c' ) ),
|
420
|
+
|
421
|
+
esc_html( get_the_date() ),
|
422
|
+
|
423
|
+
esc_attr( get_the_modified_date( 'c' ) ),
|
424
|
+
|
425
|
+
esc_html( get_the_modified_date() )
|
426
|
+
|
427
|
+
);
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
$posted_on = sprintf(
|
432
|
+
|
433
|
+
esc_html_x( '投稿日:%s', 'post date', 'underscores' ),
|
434
|
+
|
435
|
+
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
|
436
|
+
|
437
|
+
);
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
$byline = sprintf(
|
442
|
+
|
443
|
+
esc_html_x( 'by %s', 'post author', 'underscores' ),
|
444
|
+
|
445
|
+
'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
|
446
|
+
|
447
|
+
);
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
echo '<span class="posted-on">' . $posted_on . '</span>'; // WPCS: XSS OK.
|
452
|
+
|
453
|
+
}
|
454
|
+
|
455
|
+
endif;
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
if ( ! function_exists( 'underscores_entry_footer' ) ) :
|
460
|
+
|
461
|
+
/**
|
462
|
+
|
463
|
+
* Prints HTML with meta information for the categories, tags and comments.
|
464
|
+
|
465
|
+
*/
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
function underscores_entry_footer() {
|
470
|
+
|
471
|
+
// Hide category and tag text for pages.
|
472
|
+
|
473
|
+
if ( 'post'||'blog' === get_post_type() ) {
|
474
|
+
|
475
|
+
/* translators: used between list items, there is a space after the comma */
|
476
|
+
|
477
|
+
$categories_list = get_the_category_list( esc_html__( ', ', 'underscores' ) );
|
478
|
+
|
479
|
+
if ( $categories_list && underscores_categorized_blog() ) {
|
480
|
+
|
481
|
+
printf( '<p class="cat-links">' . esc_html__( 'カテゴリー:%1$s', 'underscores' ) . '</p>', $categories_list ); // WPCS: XSS OK.
|
482
|
+
|
483
|
+
}
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
/* translators: used between list items, there is a space after the comma */
|
488
|
+
|
489
|
+
$tags_list = get_the_tag_list( '', esc_html__( ', ', 'underscores' ) );
|
490
|
+
|
491
|
+
if ( $tags_list ) {
|
492
|
+
|
493
|
+
printf( '<p class="tags-links">' . esc_html__( 'タグ:%1$s', 'underscores' ) . '</p>', $tags_list ); // WPCS: XSS OK.
|
494
|
+
|
495
|
+
}
|
496
|
+
|
497
|
+
}
|
498
|
+
|
499
|
+
//カスタム投稿タイプのアーカイブ ※追加しました
|
500
|
+
|
501
|
+
if ( 'blog' === get_post_type() ) {
|
502
|
+
|
503
|
+
the_taxonomies( $args );
|
504
|
+
|
505
|
+
}
|
506
|
+
|
507
|
+
if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
|
508
|
+
|
509
|
+
echo '<span class="comments-link">';
|
510
|
+
|
511
|
+
/* translators: %s: post title */
|
512
|
+
|
513
|
+
comments_popup_link( sprintf( wp_kses( __( 'Leave a Comment<span class="screen-reader-text"> on %s</span>', 'underscores' ), array( 'span' => array( 'class' => array() ) ) ), get_the_title() ) );
|
514
|
+
|
515
|
+
echo '</span>';
|
516
|
+
|
517
|
+
}
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
}
|
522
|
+
|
523
|
+
endif;
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
/**
|
528
|
+
|
529
|
+
* Returns true if a blog has more than 1 category.
|
530
|
+
|
531
|
+
*/
|
532
|
+
|
533
|
+
function underscores_categorized_blog() {
|
534
|
+
|
535
|
+
if ( false === ( $all_the_cool_cats = get_transient( 'underscores_categories' ) ) ) {
|
536
|
+
|
537
|
+
// Create an array of all the categories that are attached to posts.
|
538
|
+
|
539
|
+
$all_the_cool_cats = get_categories( array(
|
540
|
+
|
541
|
+
'fields' => 'ids',
|
542
|
+
|
543
|
+
'hide_empty' => 1,
|
544
|
+
|
545
|
+
// We only need to know if there is more than one category.
|
546
|
+
|
547
|
+
'number' => 2,
|
548
|
+
|
549
|
+
) );
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
// Count the number of categories that are attached to the posts.
|
554
|
+
|
555
|
+
$all_the_cool_cats = count( $all_the_cool_cats );
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
set_transient( 'underscores_categories', $all_the_cool_cats );
|
560
|
+
|
561
|
+
}
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
if ( $all_the_cool_cats > 1 ) {
|
566
|
+
|
567
|
+
// This blog has more than 1 category so underscores_categorized_blog should return true.
|
568
|
+
|
569
|
+
return true;
|
570
|
+
|
571
|
+
} else {
|
572
|
+
|
573
|
+
// This blog has only 1 category so underscores_categorized_blog should return false.
|
574
|
+
|
575
|
+
return false;
|
576
|
+
|
577
|
+
}
|
578
|
+
|
579
|
+
}
|
580
|
+
|
581
|
+
|
582
|
+
|
583
|
+
/**
|
584
|
+
|
585
|
+
* Flush out the transients used in underscores_categorized_blog.
|
586
|
+
|
587
|
+
*/
|
588
|
+
|
589
|
+
function underscores_category_transient_flusher() {
|
590
|
+
|
591
|
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
592
|
+
|
593
|
+
return;
|
594
|
+
|
595
|
+
}
|
596
|
+
|
597
|
+
// Like, beat it. Dig?
|
598
|
+
|
599
|
+
delete_transient( 'underscores_categories' );
|
600
|
+
|
601
|
+
}
|
602
|
+
|
603
|
+
add_action( 'edit_category', 'underscores_category_transient_flusher' );
|
604
|
+
|
605
|
+
add_action( 'save_post', 'underscores_category_transient_flusher' );
|
606
|
+
|
607
|
+
|
374
608
|
|
375
609
|
```
|
376
|
-
|
377
|
-
### 試したこと2
|
378
|
-
|
379
|
-
以下に「wp_list_categories('title_li=&taxonomy=blog_category,blog_tag');」と「if ( 'post'||'blog'~」を追加してみました
|
380
|
-
|
381
|
-
```php
|
382
|
-
|
383
|
-
//template-tags.php
|
384
|
-
|
385
|
-
<?php
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
if ( ! function_exists( 'underscores_posted_on' ) ) :
|
390
|
-
|
391
|
-
/**
|
392
|
-
|
393
|
-
* Prints HTML with meta information for the current post-date/time and author.
|
394
|
-
|
395
|
-
*/
|
396
|
-
|
397
|
-
function underscores_posted_on() {
|
398
|
-
|
399
|
-
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
|
400
|
-
|
401
|
-
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
|
402
|
-
|
403
|
-
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
|
404
|
-
|
405
|
-
}
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
$time_string = sprintf( $time_string,
|
410
|
-
|
411
|
-
esc_attr( get_the_date( 'c' ) ),
|
412
|
-
|
413
|
-
esc_html( get_the_date() ),
|
414
|
-
|
415
|
-
esc_attr( get_the_modified_date( 'c' ) ),
|
416
|
-
|
417
|
-
esc_html( get_the_modified_date() )
|
418
|
-
|
419
|
-
);
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
$posted_on = sprintf(
|
424
|
-
|
425
|
-
esc_html_x( '投稿日:%s', 'post date', 'underscores' ),
|
426
|
-
|
427
|
-
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
|
428
|
-
|
429
|
-
);
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
$byline = sprintf(
|
434
|
-
|
435
|
-
esc_html_x( 'by %s', 'post author', 'underscores' ),
|
436
|
-
|
437
|
-
'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
|
438
|
-
|
439
|
-
);
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
echo '<span class="posted-on">' . $posted_on . '</span>'; // WPCS: XSS OK.
|
444
|
-
|
445
|
-
}
|
446
|
-
|
447
|
-
endif;
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
if ( ! function_exists( 'underscores_entry_footer' ) ) :
|
452
|
-
|
453
|
-
/**
|
454
|
-
|
455
|
-
* Prints HTML with meta information for the categories, tags and comments.
|
456
|
-
|
457
|
-
*/
|
458
|
-
|
459
|
-
//カスタム投稿を追加
|
460
|
-
|
461
|
-
wp_list_categories('title_li=&taxonomy=blog_category,blog_tag');
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
function underscores_entry_footer() {
|
466
|
-
|
467
|
-
// Hide category and tag text for pages.
|
468
|
-
|
469
|
-
if ( 'post'||'blog' === get_post_type() ) {
|
470
|
-
|
471
|
-
/* translators: used between list items, there is a space after the comma */
|
472
|
-
|
473
|
-
$categories_list = get_the_category_list( esc_html__( ', ', 'underscores' ) );
|
474
|
-
|
475
|
-
if ( $categories_list && underscores_categorized_blog() ) {
|
476
|
-
|
477
|
-
printf( '<p class="cat-links">' . esc_html__( 'カテゴリー:%1$s', 'underscores' ) . '</p>', $categories_list ); // WPCS: XSS OK.
|
478
|
-
|
479
|
-
}
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
/* translators: used between list items, there is a space after the comma */
|
484
|
-
|
485
|
-
$tags_list = get_the_tag_list( '', esc_html__( ', ', 'underscores' ) );
|
486
|
-
|
487
|
-
if ( $tags_list ) {
|
488
|
-
|
489
|
-
printf( '<p class="tags-links">' . esc_html__( 'タグ:%1$s', 'underscores' ) . '</p>', $tags_list ); // WPCS: XSS OK.
|
490
|
-
|
491
|
-
}
|
492
|
-
|
493
|
-
}
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
|
498
|
-
|
499
|
-
echo '<span class="comments-link">';
|
500
|
-
|
501
|
-
/* translators: %s: post title */
|
502
|
-
|
503
|
-
comments_popup_link( sprintf( wp_kses( __( 'Leave a Comment<span class="screen-reader-text"> on %s</span>', 'underscores' ), array( 'span' => array( 'class' => array() ) ) ), get_the_title() ) );
|
504
|
-
|
505
|
-
echo '</span>';
|
506
|
-
|
507
|
-
}
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
}
|
512
|
-
|
513
|
-
endif;
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
/**
|
518
|
-
|
519
|
-
* Returns true if a blog has more than 1 category.
|
520
|
-
|
521
|
-
*/
|
522
|
-
|
523
|
-
function underscores_categorized_blog() {
|
524
|
-
|
525
|
-
if ( false === ( $all_the_cool_cats = get_transient( 'underscores_categories' ) ) ) {
|
526
|
-
|
527
|
-
// Create an array of all the categories that are attached to posts.
|
528
|
-
|
529
|
-
$all_the_cool_cats = get_categories( array(
|
530
|
-
|
531
|
-
'fields' => 'ids',
|
532
|
-
|
533
|
-
'hide_empty' => 1,
|
534
|
-
|
535
|
-
// We only need to know if there is more than one category.
|
536
|
-
|
537
|
-
'number' => 2,
|
538
|
-
|
539
|
-
) );
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
// Count the number of categories that are attached to the posts.
|
544
|
-
|
545
|
-
$all_the_cool_cats = count( $all_the_cool_cats );
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
set_transient( 'underscores_categories', $all_the_cool_cats );
|
550
|
-
|
551
|
-
}
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
if ( $all_the_cool_cats > 1 ) {
|
556
|
-
|
557
|
-
// This blog has more than 1 category so underscores_categorized_blog should return true.
|
558
|
-
|
559
|
-
return true;
|
560
|
-
|
561
|
-
} else {
|
562
|
-
|
563
|
-
// This blog has only 1 category so underscores_categorized_blog should return false.
|
564
|
-
|
565
|
-
return false;
|
566
|
-
|
567
|
-
}
|
568
|
-
|
569
|
-
}
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
/**
|
574
|
-
|
575
|
-
* Flush out the transients used in underscores_categorized_blog.
|
576
|
-
|
577
|
-
*/
|
578
|
-
|
579
|
-
function underscores_category_transient_flusher() {
|
580
|
-
|
581
|
-
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
582
|
-
|
583
|
-
return;
|
584
|
-
|
585
|
-
}
|
586
|
-
|
587
|
-
// Like, beat it. Dig?
|
588
|
-
|
589
|
-
delete_transient( 'underscores_categories' );
|
590
|
-
|
591
|
-
}
|
592
|
-
|
593
|
-
add_action( 'edit_category', 'underscores_category_transient_flusher' );
|
594
|
-
|
595
|
-
add_action( 'save_post', 'underscores_category_transient_flusher' );
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
```
|
3
マーク追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
しかしどうしてもカスタムタクソノミーの情報(カテゴリーやタグ)の情報を出すことができず四苦八苦しております。どうかお知恵をお貸しください・・・
|
11
|
+
しかしどうしてもカスタムタクソノミーの情報(カテゴリーやタグ)の情報を出すことができず四苦八苦しております。どうかお知恵をお貸しください・・・
|
12
12
|
|
13
13
|
|
14
14
|
|
2
内容を修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
wordpressのカスタム投稿タイプ(+カスタムタクソノミーも)をプラグインに頼らず
|
1
|
+
wordpressのカスタム投稿タイプ(+カスタムタクソノミーも)をプラグインに頼らず表示したい
|
test
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
### 試したこと1
|
6
|
+
|
5
|
-
すでに解決済みの[こちらのページ](https://teratail.com/questions/33577)を参考にし、カスタム投稿一覧・記事ページで本文の表示はできました。しかしそのままでは日付が表示できなかったため、修正して
|
7
|
+
すでに解決済みの[こちらのページ](https://teratail.com/questions/33577)を参考にし、カスタム投稿一覧・記事ページで本文の表示はできました。しかしそのままでは日付が表示できなかったため、修正して日付は表示できました。
|
6
8
|
|
7
9
|
|
8
10
|
|
@@ -372,7 +374,9 @@
|
|
372
374
|
|
373
375
|
```
|
374
376
|
|
377
|
+
### 試したこと2
|
378
|
+
|
375
|
-
以下
|
379
|
+
以下に「wp_list_categories('title_li=&taxonomy=blog_category,blog_tag');」と「if ( 'post'||'blog'~」を追加してみました
|
376
380
|
|
377
381
|
```php
|
378
382
|
|
@@ -452,7 +456,7 @@
|
|
452
456
|
|
453
457
|
*/
|
454
458
|
|
455
|
-
//カスタム投稿を追加
|
459
|
+
//カスタム投稿を追加
|
456
460
|
|
457
461
|
wp_list_categories('title_li=&taxonomy=blog_category,blog_tag');
|
458
462
|
|
1
書式の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
wordpressのカスタム投稿タイプ(+カスタムタクソノミーも)をプラグインに頼らず利用したいと思い書き込みいたしました。
|
1
|
+
wordpressのカスタム投稿タイプ(+カスタムタクソノミーも)をプラグインに頼らず利用したいと思い書き込みいたしました。※テーマは _s(underscores)をカスタマイズして利用しています
|
2
|
-
|
3
|
-
※テーマは _s(underscores)をカスタマイズして利用しています
|
4
2
|
|
5
3
|
|
6
4
|
|
@@ -8,11 +6,7 @@
|
|
8
6
|
|
9
7
|
|
10
8
|
|
11
|
-
しかしどうしてもカスタムタクソノミーの情報(カテゴリーやタグ)の情報を出すことができず四苦八苦しております。
|
9
|
+
しかしどうしてもカスタムタクソノミーの情報(カテゴリーやタグ)の情報を出すことができず四苦八苦しております。どうかお知恵をお貸しください・・・!
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
どうかお知恵をお貸しください・・・!
|
16
10
|
|
17
11
|
|
18
12
|
|