2017-06-18 56 views
1

我使用兩個插件WPCustom範疇圖片爲了能在每個類別和W4郵冊的列表屏幕上的類別,以插入圖像。如何得到正確的term_id每篇文章

在這一刻,給我總是最後一個圖像的類別。我假裝每個類別對應於每個ID的圖像。

該插件有一個短代碼[term_id],它顯示相應的類別ID,但我不能從另一個短代碼中使用一個短代碼。

- [wp_custom_image_category onlysrc = 「假」 大小= 「滿」 term_id = 「[term_id」]]

任何溶液?

foreach(get_categories(['hide_empty' => false]) as $category) { 
    $image = do_shortcode('[wp_custom_image_category onlysrc="false" size="full" term_id="'.$category->term_id.'" ]'); 
    echo $image.'<br/>'; 

    // $id = 4; 
    $options['template'] = 
    '[terms] 
     <div class="col-sm-3 news-cat-links" id="[term_id]"> 
      <a href="[term_link]">[term_name]</a><img src="'.$image.'" /></a> 
    </div>[/terms]'; 
    } 

回答

0

轉到相應的插件文件,找到[term_id]短代碼的功能。

0

下面的代碼返回名爲「eventcategory」的自定義texanomy的數組。將$ post定義爲全局變量。

 $terms = get_the_terms($post->ID, 'eventcategory'); 
      if ($terms && ! is_wp_error($terms)) : 
       $draught_links = array(); 
      foreach ($terms as $term) { 
        $draught_links[] = $term->name; 
       } 
     print_r($draught_links); 
相關問題