質問編集履歴
1
ソースコードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -111,3 +111,97 @@
|
|
111
111
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
112
112
|
|
113
113
|
wordpress 4.6.1を使っています。
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
###追記
|
118
|
+
|
119
|
+
```
|
120
|
+
|
121
|
+
<?php
|
122
|
+
|
123
|
+
$args = array(
|
124
|
+
|
125
|
+
'orderby' => 'term_order',
|
126
|
+
|
127
|
+
'order' => 'ASC',
|
128
|
+
|
129
|
+
'parent' => 0,
|
130
|
+
|
131
|
+
'hierarhical' => 0
|
132
|
+
|
133
|
+
);
|
134
|
+
|
135
|
+
$my_taxonomy = 'media_info';//カスタム分類(カスタムタクソノミー)
|
136
|
+
|
137
|
+
$terms = get_terms($my_taxonomy,$args);
|
138
|
+
|
139
|
+
if ( ! empty( $terms ) && ! is_wp_error( $terms )):
|
140
|
+
|
141
|
+
foreach ( $terms as $term ): ?>
|
142
|
+
|
143
|
+
<h3><?php echo esc_html($term->name); ?></h3>
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
<?php
|
148
|
+
|
149
|
+
$count = $term->count; //タームの記事数取得
|
150
|
+
|
151
|
+
$link = get_term_link($term->slug, $term->taxonomy); //タームのリンクを取得
|
152
|
+
|
153
|
+
$tax_posts = new WP_Query(array(
|
154
|
+
|
155
|
+
'post_type' => 'media_info',
|
156
|
+
|
157
|
+
'posts_per_page' => 2,
|
158
|
+
|
159
|
+
'tax_query' => array(
|
160
|
+
|
161
|
+
array(
|
162
|
+
|
163
|
+
'taxonomy' => 'media_info',//カスタム分類(カスタムタクソノミー)
|
164
|
+
|
165
|
+
'terms' => array($term->slug),
|
166
|
+
|
167
|
+
'field' =>'slug',
|
168
|
+
|
169
|
+
)
|
170
|
+
|
171
|
+
),
|
172
|
+
|
173
|
+
));
|
174
|
+
|
175
|
+
if ($tax_posts->have_posts()) : ?>
|
176
|
+
|
177
|
+
<div class="media-cat">
|
178
|
+
|
179
|
+
<?php while ($tax_posts-> have_posts()) : $tax_posts->the_post(); ?>
|
180
|
+
|
181
|
+
<div class="media_info">
|
182
|
+
|
183
|
+
<iframe src="https://www.youtube.com/embed/<?php the_field('media_youtube'); ?>" frameborder="0" allowfullscreen></iframe>
|
184
|
+
|
185
|
+
</div>
|
186
|
+
|
187
|
+
<?php endwhile; ?>
|
188
|
+
|
189
|
+
<div class="clrfx"></div>
|
190
|
+
|
191
|
+
<p><?php echo $term->description; ?></p>
|
192
|
+
|
193
|
+
<?php wp_reset_postdata(); ?>
|
194
|
+
|
195
|
+
<?php if($count >= 3): ?> //タームの記事数が3以上ならmoreボタンを表示
|
196
|
+
|
197
|
+
<a href="<?php echo $link; ?>"><div class="media-more">More</div></a>
|
198
|
+
|
199
|
+
<?php endif; ?>
|
200
|
+
|
201
|
+
</div>
|
202
|
+
|
203
|
+
<?php endif; endforeach; endif; ?>
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
```
|