WordPressでカテゴリー一覧へのリンクを表示する

ページ内でカテゴリのリンクを表示する場合は

get_categories( )関数を利用

<?php
    
    $args = array(

// 親カテゴリーのものだけを一覧で取得
        'parent' => 0,
        'orderby' => 'term_order',
        'order' => 'ASC'
    );

//$categoriesに詰め込む
    $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

//slug が newsのオブジェクトを詰め込む
                $news = get_term_by( 'slug', 'news','category');

//カテゴリへのリンクを生成 第2引数はタクソノミ
                $news_link = get_term_link( $news, 'category' );
                var_dump($news);

//===$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>