質問編集履歴
1
ソースコードの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -54,4 +54,51 @@
|
|
54
54
|
```
|
55
55
|
|
56
56
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
57
|
-
wordpress 4.6.1を使っています。
|
57
|
+
wordpress 4.6.1を使っています。
|
58
|
+
|
59
|
+
###追記
|
60
|
+
```
|
61
|
+
<?php
|
62
|
+
$args = array(
|
63
|
+
'orderby' => 'term_order',
|
64
|
+
'order' => 'ASC',
|
65
|
+
'parent' => 0,
|
66
|
+
'hierarhical' => 0
|
67
|
+
);
|
68
|
+
$my_taxonomy = 'media_info';//カスタム分類(カスタムタクソノミー)
|
69
|
+
$terms = get_terms($my_taxonomy,$args);
|
70
|
+
if ( ! empty( $terms ) && ! is_wp_error( $terms )):
|
71
|
+
foreach ( $terms as $term ): ?>
|
72
|
+
<h3><?php echo esc_html($term->name); ?></h3>
|
73
|
+
|
74
|
+
<?php
|
75
|
+
$count = $term->count; //タームの記事数取得
|
76
|
+
$link = get_term_link($term->slug, $term->taxonomy); //タームのリンクを取得
|
77
|
+
$tax_posts = new WP_Query(array(
|
78
|
+
'post_type' => 'media_info',
|
79
|
+
'posts_per_page' => 2,
|
80
|
+
'tax_query' => array(
|
81
|
+
array(
|
82
|
+
'taxonomy' => 'media_info',//カスタム分類(カスタムタクソノミー)
|
83
|
+
'terms' => array($term->slug),
|
84
|
+
'field' =>'slug',
|
85
|
+
)
|
86
|
+
),
|
87
|
+
));
|
88
|
+
if ($tax_posts->have_posts()) : ?>
|
89
|
+
<div class="media-cat">
|
90
|
+
<?php while ($tax_posts-> have_posts()) : $tax_posts->the_post(); ?>
|
91
|
+
<div class="media_info">
|
92
|
+
<iframe src="https://www.youtube.com/embed/<?php the_field('media_youtube'); ?>" frameborder="0" allowfullscreen></iframe>
|
93
|
+
</div>
|
94
|
+
<?php endwhile; ?>
|
95
|
+
<div class="clrfx"></div>
|
96
|
+
<p><?php echo $term->description; ?></p>
|
97
|
+
<?php wp_reset_postdata(); ?>
|
98
|
+
<?php if($count >= 3): ?> //タームの記事数が3以上ならmoreボタンを表示
|
99
|
+
<a href="<?php echo $link; ?>"><div class="media-more">More</div></a>
|
100
|
+
<?php endif; ?>
|
101
|
+
</div>
|
102
|
+
<?php endif; endforeach; endif; ?>
|
103
|
+
|
104
|
+
```
|