ページ内でカテゴリのリンクを表示する場合は
get_categories( )関数を利用
<?php
$args = array(
'parent' => 0,
'orderby' => 'term_order',
'order' => 'ASC'
);
$categories = get_categories( $args );
?>
//ループで回す
<?php foreach( $categories as $category ) : ?>
<li>
<a href="<?php echo get_category_link( $category->term_id ); ?>"><?php echo $category->name; ?></a>
</li>
<?php endforeach; ?>
カテゴリーへのリンクを表示する場合は
get_term_by( ) 関数と
get_term_link( )関数を利用する
<?php
$news = get_term_by( 'slug', 'news','category');
$news_link = get_term_link( $news, 'category' );
var_dump($news);
public 'term_id' => int 3
public 'name' => string 'news' (length=4)
public 'slug' => string 'news' (length=4)
public 'term_group' => int 0
public 'term_taxonomy_id' => int 3
public 'taxonomy' => string 'category' (length=8)
public 'description' => string '' (length=0)
public 'parent' => int 0
public 'count' => int 3
public 'filter' => string 'raw' (length=3)
?>
//リンクを出力
<a href="<?= $news_link ?>" class="btn btn-default">最新情報の一覧<i class="fas fa-angle-right"></i></a>