ヘッダ画像をページ毎に違う画像にしたい場合、アイキャッチを使う方法と、cssで画像を切り替える方法など色々ありますが、
今回は分岐を使って変更する方法です。
<?php if(is_page(TOP)) : ?> <img src="<?php bloginfo('template_url'); ?>/images/○○○.jpg" width="950" height="294" />//TOPページのみ表示 <?php elseif(is_page(ABOUT)) : ?> <img src="<?php bloginfo('template_url'); ?>/images/○○○.jpg" width="950" height="210" />//特定の固定ページにみ表示 <?php elseif(is_category(4)) : ?> <?php $category = &get_category(get_query_var('cat')); ?> <img alt="" src="<?php bloginfo('template_url'); ?>/images/○○○.jpg" />//カテゴリーID 4のアーカイブページが表示されている場合。 <?php elseif(in_category(5)) : ?> <?php $category = &get_category(get_query_var('cat')); ?> <img alt="" src="<?php bloginfo('template_url'); ?>/images/○○○.jpg" />//(in_category です。) 現在の投稿がカテゴリーID5に属する場合にtrueを返します。 <?php endif; ?>
<?php if (is_page(TOP)) {?> <p></p> <?php } else if (is_category(16)) { ?> <img src="/images/ttl_official_blog.jpg" width="780" height="101" alt="オフィシャルブログ " /> <?php } else if (is_category(17)) { ?> <img src="/images/ttl_members.jpg" width="780" height="101" alt="メンバーズブログ " /> <?php } ?> <?php if ( get_post_type() === 'qa' ):// カスタム投稿名 ?> <img src="/images/ttl_qa.jpg" width="780" height="101" alt="住まいのQ&A " /> <?php endif; ?> <?php if ( get_post_type() === 'topics' ):// カスタム投稿名 ?> <img src="/images/ttl_topics" width="780" height="101" alt="トピックス " /> <?php endif; ?> <?php if( is_month() ) : // 月別ページの場合 ?> <img src="/wordpress/wp-content/themes/lifecrayon/images/ttl_topics" width="780" height="101" alt="トピックス " /> <?php endif; ?>
<?php if(is_page()): ?> 固定ページの場合のみ表示 <?php elseif(is_single()): ?> <?php if ( get_post_type() === '投稿タイプ名' ): ?> 指定されたカスタム投稿タイプ名の場合のみ表示 <?php else: ?> 投稿の個別ページの場合のみ表示 <?php endif; ?> <?php elseif(is_category()): ?> カテゴリーページの場合のみ表示 <?php elseif(is_post_type_archive('カスタム投稿タイプ名')): ?> 指定されたカスタム投稿タイプ名のアーカイブページの場合のみ表示 <?php elseif(is_tax('カスタム分類名')): ?> 指定されたカスタム分類名ページの場合のみ表示 <?php elseif(is_tag()): ?> タグのアーカイブページtag.phpの場合のみ表示 <?php elseif(is_search()): ?> 検索結果ページの場合のみ表示 <?php elseif(is_404()): ?> 404ページの場合のみ表示 <?php else: ?> それ以外 <?php endif; ?>
<?php if ( is_object_in_term($post->ID, 'topics','event') ): ?> //topicsがカスタム投稿名 eventが分類名 <img src="/images/ttl_topics" width="780" height="101" alt="トピックス " /> <?php endif; ?>
<?php if (is_home()) {?> <p></p> <?php } else if (is_page(会員登録・お問合せ・資料請求)) { ?> <h1><img src="/images/ttl_form.gif" width="500" height="27" alt="会員登録・お問合せ・資料請求" /></h1> <?php } else{ ?> <h1 class="p-title"><?php the_title(); ?></h1> <?php } ?>
<?php if ( in_category('16') ) { include(TEMPLATEPATH . '/sidebar-blog'); } else if ( in_category('17') ) { include(TEMPLATEPATH . '/sidebar-members.php'); } ?>
<?php if(have_posts()): while(have_posts()): the_post(); ?> <?php $postID = get_the_ID(); $terms = get_the_terms($postID,'カスタム分類名'); foreach ( $terms as $term ) { $tslug = esc_html($term->slug); } ?> <?php endwhile; endif; ?> <?php if($tslug === 'ターム名1'): ?> あああ <?php elseif($tslug === 'ターム名2'): ?> あああ <?php endif; ?>
<?php if (is_category('news')) { ?> <h1>NEWS</h1>//親カテゴリーをスラッグ名で所得。親カテゴリーのみに表示 <?php } ?> <?php if (cat_is_ancestor_of(5, $cat)) { ?> <h1>イベント</h1>//ID5を親カテゴリーに持つ子カテゴリーのみに表示 <?php } ?>
<?php if ( get_post_type() === 'blog' ): ?> 投稿タイプ名がblogの時アーカイブページとシングルページに対応 <?php endif; ?>
<?php if(is_post_type_archive()): ?> カスタム投稿タイプのアーカイブページの時のみ表示 <?php endif; ?>