WordPressでカテゴリの関連情報を取得
現在のページのカテゴリに関する情報を取得します。
single.php
<?php
$cat = get_the_category();
$cat = $cat[0];
$cat_name = $cat->name;
$cat_id = $cat->cat_ID;
$cat_slug = $cat->slug;
$cat_term = $cat->term_id;
$cat_termid = $cat->term_taxonomy_id;
$cat_taxonomy = $cat->taxonomy;
$cat_count = $cat->count;
$cat_description = $cat->category_description;
$parent_id = $cat->category_parent;
$parent = get_category($cat->category_parent);
$parent_catname = $parent->cat_name;
?>
カテゴリアーカイブへのリンクを取得
上記のコードで取得したIDでアーカイブへのリンクを取得します。
single.php
<a href="<?php echo esc_url(get_category_link($cat_id)); ?>"></a>
おわります。