Last active
December 28, 2015 11:58
-
-
Save mypacecreator/7496805 to your computer and use it in GitHub Desktop.
single.phpで、カテゴリースラッグを元にタイトル画像を表示する(子カテゴリーの場合も、親カテゴリーの画像を使う)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cat = get_the_category(); | |
if ($cat[0]->category_parent): //子カテゴリの場合 | |
$parent_cat = get_category($cat[0]->category_parent); | |
?> | |
<p class="title"><img src="<?php echo get_template_directory_uri(); ?>/images/title_<?php echo $parent_cat->slug; ?>.jpg" alt="<?php echo $parent_cat->name; ?>" /></p> | |
<p class="subtitle"><?php echo $cat[0]->cat_name; ?></p> | |
<?php else: //親カテゴリの場合 ?> | |
<p class="title"><img src="<?php echo get_template_directory_uri(); ?>/images/title_<?php echo $cat[0]->category_nicename; ?>.jpg" alt="<?php echo $cat[0]->cat_name; ?>" /></p> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment