2017-06-18 7 views
1

の正しいterm_idを取得する方法。各カテゴリーおよびリスト画面上のカテゴリーの<strong>W4ポスト一覧</strong>に画像を挿入することができるため、私は2つのプラグイン<strong>WPCustomカテゴリイメージ</strong>を使用しています各記事

この瞬間、常にカテゴリの最後のイメージを与えてください。私は各IDに対応する各カテゴリーのイメージをふりまとめています。

プラグインには、対応するカテゴリIDを示す1つのshortcode [term_id]がありますが、別のショートコードから1つのshortcodeを使用することはできません。

- [wp_custom_image_category onlysrc = "false" のサイズ= "フル" 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"というカスタムテキサノミーの配列を返します。 $ 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); 
関連する問題

 関連する問題