Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
カテゴリとタグ、投稿日を表示させる。
<?php
$categories = get_the_category();
$tags = get_the_tags();
if(!empty($tags) || !empty($categories) ):?>
<?php if(!empty($categories)):
foreach($categories as $category ):?>
<ul>
<li class="category_name">
<a href="<?php echo get_category_link($category->term_id);?>">
<?php echo $category->name;?>
</a>
</li>
</ul>
<?php endforeach;?>
<?php endif;?>
<?php if(!empty($tags)):
foreach($tags as $tag ):?>
<ul>
<li class="tag_name">
<a href="<?php echo get_category_link($tag->term_id);?>">
<?php echo $tag->name;?>
</a>
</li>
</ul>
<?php endforeach;?>
<?php endif;?>
<?php endif;?>
<?php the_time('Y年n月j日'); ?>
@pochi-web

This comment has been minimized.

Copy link
Owner Author

commented Sep 24, 2017

$categories = get_the_category();
$tags = get_the_tags();

でカテゴリとタグのオブジェクトを取得、代入

ifでそれぞれのオブジェクトがあれば表示、なければ非表示。の条件分岐。
category_linkの引数にget_the_categoryで取得した配列の一つ"term_id"を使用して、URLを取得する。

以下同様。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.