目次
「カテゴリの画像」カスタムフィールドを作成する
Toolset Typesプラグインでのやり方をメモ。
カテゴリ/タームの説明文は「用語フィールド」
カテゴリの説明文(タームの説明文)を登録するには「用語フィールド(Term Field )」の追加をします。
カテゴリ/タームのに追加した画像フィールドの出力は「types_render_termmeta」
<?php echo (types_render_termmeta("cat_img", array("term_id" => 1))); ?>
“term_id” => 1 というように出したいタームのterm_idが要ります。
カテゴリ一覧+画像 という場合の表示方法は下記のようなコードで。
<?php
$taxonomy = 'category';
$term_args = array(
'hide_empty' => false,
);
$tax_terms = get_terms($taxonomy, $term_args);
$description = term_description();
?>
<?php
foreach ($tax_terms as $tax_term):?>
<a href="<?php echo esc_attr(get_term_link($tax_term, $taxonomy));?>">
<h3><?php echo $tax_term->name ; ?></h3>
<?php echo (types_render_termmeta("cat_img", array("term_id" => $tax_term->term_id))); ?>
</a>
<?php endforeach; ?>
コメント