Skip to content

Instantly share code, notes, and snippets.

@mypacecreator
Last active Dec 28, 2015
Embed
What would you like to do?
アーカイプページで、カテゴリースラッグを元にタイトル画像を表示する(子カテゴリーの場合も、親カテゴリーの画像を使う)
<?php if(is_category()): ?>
<?php
$cat_id = get_query_var('cat');
$cat = get_category($cat_id);
$cat_parent_id = $cat->category_parent;
$cat_parent = get_category($cat_parent_id);
if( $cat_parent_id == 0 ): //親カテゴリの場合
$cat_parent = get_category($cat_parent_id);
?>
<p class="title"><img src="<?php echo get_template_directory_uri(); ?>/images/title_<?php echo $cat->category_nicename; ?>.jpg" alt="<?php single_cat_title(); ?>" /></p>
<?php else: //子カテゴリの場合 ?>
<p class="title"><img src="<?php echo get_template_directory_uri(); ?>/images/title_<?php echo $cat_parent->slug; ?>.jpg" alt="<?php echo get_cat_name($cat_parent_id); ?>" /></p>
<h1 class="subtitle"><?php single_cat_title(); ?></h1>
<?php endif; ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment