0
我的代碼主要是工作,但有一個小問題。WordPress的列表中的所有類別和帖子
我期待看到這樣的輸出...
貓
- 國內
- Ragdol
狗
- 帕格
- 警犬
但不是我越來越:
貓
- 國內
- Ragdol
- 帕格
- 個獵犬
狗
- 國內
- Ragdol
- 帕格
- 警犬
正如你所看到的每一個崗位,在每個類別中被列,而不是隻是每個職位的帖子(對不起 - 無意雙關)各自的類別。
這裏是我的代碼:
<?php
$cat_args = array(
'taxonomy' => 'animal_category'
);
$categories = get_categories($cat_args);
foreach ($categories as $category) {
$category_hero = get_field('hero', $taxonomy . '_' . $category->term_id); ?>
<div class="gallery">
<div class="gallery-hero">
<h2><?php echo $category->name; ?></h2>
<img src="<?php echo $category_hero["sizes"]["Full"]; ?>" />
</div>
<?php
$cat_ID = $category->id;
$post_args = array(
'showposts' => -1,
'post_type' => 'gallery',
'offset' => 0,
'category' => $cat_ID
);
$posts = get_posts($post_args);
foreach($posts as $post) { ?>
<div class="gallery-box">
<?php $gallery_image = get_field("photos"); ?>
<a href="<?php the_permalink() ?>">
<img src="<?php echo $gallery_image[0]["sizes"]["Medium"]; ?>" />
<span><?php the_title(); ?></span>
</a>
</div>
<?php } ?>
</div>
一切看起來我的權利。我究竟做錯了什麼?
檢查此鏈接:http://stackoverflow.com/questions/25502227/display-posts-category-wise –