テンプレートタグの get_the_category() を使ってカテゴリー名を取得させる方法。
<?php
$cat = get_the_category();
$cat_name = $cat[0]; { echo $cat->cat_name;
?>
カテゴリー名をカテゴリーアーカイブにリンクさせるには
<?php
$cat= get_the_category();
if ( $cat[0] ) {
echo '<a href="' . get_category_link( $cat[0]->term_id ) . '">' . $cat[0]->cat_name . '</a>';
}
?>
戻り値もついでに…
stdClass Object
(
[term_id] =>
[name] =>
[slug] =>
[term_group] =>
[term_order] =>
[term_taxonomy_id] =>
[taxonomy] =>
[description] =>
[parent] =>
[count] =>
[object_id] =>
)
コメントを残す