Created
February 9, 2014 05:51
-
-
Save snoise/8894928 to your computer and use it in GitHub Desktop.
(トップページのみ)アイキャッチ画像(サムネイル)を、カテゴリ毎にサイズを分けて表示するWordpressプラグイン
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 | |
/* | |
Plugin Name: paka3_category_thumb | |
Plugin URI: http://www.paka3.com/wpplugin | |
Description: アイキャッチ画像(サムネイル)を、カテゴリ毎にサイズを分けて表示する | |
Author: Shoji ENDO | |
Version: 0.1 | |
Author URI:http://www.paka3.com/ | |
*/ | |
if (function_exists('add_theme_support')) { | |
// アイキャッチ画像を有効 | |
add_theme_support( 'post-thumbnails' ); | |
// アイキャッチ画像[post-thumbnails]のサイズ設定 | |
set_post_thumbnail_size( 190, 190, true ); | |
// アップロードするときに変換される画像のサイズを追加する | |
add_image_size( 'thumbCategoryA', 200, 50, true ); | |
add_image_size( 'thumbCategoryB', 150, 300, true ); | |
//paka3_category_thumbの呼び出し | |
add_filter( 'post_thumbnail_html', 'paka3_category_thumb',10,3); | |
} | |
function paka3_category_thumb($html, $post_id, $post_thumbnail_id){ | |
if(is_home()){ | |
foreach(get_the_category() as $cat){ | |
//echo $cat->cat_ID; | |
if($cat->cat_ID ==3){ | |
$image = wp_get_attachment_image_src($post_thumbnail_id, 'thumbCategoryA'); | |
return "<img src=".$image[0].">"; | |
}elseif($cat->cat_ID ==12){ | |
$image = wp_get_attachment_image_src($post_thumbnail_id, 'thumbCategoryB'); | |
return "<img src=".$image[0].">"; | |
}else{ | |
return $html; | |
} | |
} | |
} | |
return $html; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment