LoginSignup
0
2

More than 5 years have passed since last update.

《WordPress》現在のページのカテゴリの関連情報を取得する

Last updated at Posted at 2017-05-26

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>

おわります。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2