2011年8月8日月曜日

WPのカテゴリ事に画像を変える

ヘッダーにphpぶっ込んで、CSSでカテゴリのidで指定する。

まずヘッダーのイメージを変更した箇所に以下をぶっ込む
///////////////////////////////////////////////////////////

<?php if( is_home() ) : // フロントページの場合 ?>

<?php elseif( is_month() ) : // 月別ページの場合 ?>

<?php else : // それ以外の場合

$cat = get_the_category();

$cat = $cat[0];

?>

<div class="cat-<?php echo $cat->cat_ID; ?>"></div>

<?php endif; ?>
///////////////////////////////////////////////////////////

それからcssで

cssの記述は下記の通り(※赤字部分は自サイトに合わせて変更)
.cat-1 {
background:url(images/head_img01.jpg) no-repeat;
width: 900px;
height: 250px;
}
.cat-2 {
background:url(images/head_img02.jpg) no-repeat;
width: 900px;
height: 250px;
}
.cat-3 {
background:url(images/head_img03.jpg) no-repeat;
width: 900px;
height: 250px;
}

をぶっ込むとやっほーだぜ!!

参考サイト
http://msweb.moo.jp/wordpress/483/




0 件のコメント:

コメントを投稿