2016-11-14 22 views
0

我試圖顯示縮略圖和標題中所選類別的所有帖子。我已經設法讓下面的代碼向我展示所選的類別,但是我似乎無法找出一個循環來顯示所選類別的每個帖子的縮略圖和標題。所選類別的後循環

<?php $taxonomy = 'category'; 
// Get the term IDs assigned to post. 
$post_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids')); 

// Separator between links. 
$separator = ', '; 

if (! empty($post_terms) && ! is_wp_error($post_terms)) { 

    $term_ids = implode(',' , $post_terms); 

    $terms = wp_list_categories(array(
     'title_li' => '', 
     'style' => 'none', 
     'echo'  => false, 
     'taxonomy' => $taxonomy, 
     'include' => $term_ids 
    )); 

    $terms = rtrim(trim(str_replace('<br />', $separator, $terms)), $separator); 

    // Display post categories. 
    echo $terms; 

} ?> 

有了這個代碼,我可以得到它顯示我的縮略圖該類別中的第一篇文章:

<a href="<?php get_the_permalink($term_id); ?>"> 
       <?php the_post_thumbnail(array(200, 200)); ?> 
      </a> 

我怎麼能循環呢?

感謝

回答

1

你好,如果你想選擇特定類別的職位試試這個link。這對我有幫助。

+0

非常感謝。我查看了鏈接,並更改了我的代碼以匹配他們的代碼,並且它工作正常。我只需要改變一下佈局以符合我的想法。 – FilT