カレンダーの日本語表記の日付を英語表示にする(jQueryで無理やり)

WordPress

<?php get_calendar(); ?>

で表示されるカレンダーを英語表記にするやつ。
単に文字列を置き換えているだけだけど、
jQuery読み込んでいること前提で。

<script type="text/javascript">
$(document).ready(function(){

	//yyyy年mm月の置換
	$('#wp-calendar caption').each(function() {
		var text = $(this).text().split("年");
		//[Month. Year]
		$(this).text(month_en(text[1]) + '. ' + text[0]);
	});

	//曜日の置換
	$('#wp-calendar th').each(function() {
		if ($(this).text() == "日") { $(this).addClass('sunday'); } 
		if ($(this).text() == "土") { $(this).addClass('saturday'); }
		$(this).text(day_en($(this).text()));
	});

	//前月の置換
	$('#wp-calendar #prev a').each(function() {
		var text = $(this).text().split(" ");
		//[< Month]
		$(this).text('< ' + month_en(text[1]));
	});

	//次月の置換
	$('#wp-calendar #next a').each(function() {
		var text = $(this).text().split(" ");
		//[Month >]
		$(this).text(month_en(text[0]) + ' >');
	});

	function day_en($text) {
		switch ($text) {
			case '日':  $text = 'S'; break;
			case '月':  $text = 'M'; break;
			case '火':  $text = 'T'; break;
			case '水':  $text = 'W'; break;
			case '木': $text = 'T'; break;
			case '金': $text = 'F'; break;
			case '土': $text = 'S'; break;
		}
		return $text;
	}

	function month_en($text) {
		switch ($text) {
			case '12月': $text = 'Dec'; break;
			case '11月': $text = 'Nov'; break;
			case '10月': $text = 'Oct'; break;
			case '9月': $text = 'Sep'; break;
			case '8月': $text = 'Aug'; break;
			case '7月': $text = 'Jul'; break;
			case '6月': $text = 'Jun'; break;
			case '5月': $text = 'May'; break;
			case '4月': $text = 'Apr'; break;
			case '3月': $text = 'Mar'; break;
			case '2月': $text = 'Feb'; break;
			case '1月': $text = 'Jan'; break;
		}
		return $text;
	}

});
</script>

jQueryのフェード系メソッド + IEで、文字が潰れる問題

タイトルの通りなのだけどIE環境で特定要素に、

$('div').fadeIn('fast');

など、フェード系のメソッド(sideToggleとかいろいろ)かけると、
文字が潰れてジャギジャギなる。
より具体的にいうと、ClearTypeWindowsの文字のアンチエイリアシング方式)が無効になるんだそう。
悔しいこれ。

IEでは、透明度を"filter"という独自仕様で指定するのだけど、
コレとフォントのClearTypeが干渉するんだって。

$('div').fadeIn('fast',function() {
	if ( !jQuery.support.leadingWhitespace ) { this.style.removeAttribute('filter'); }
});

などと、フェード系のメソッドのcallbackで、IE判定してremoveAttributeでfilter消してやればいいみたい。

テーマファイルのパス

WPをインストールしたパス基準のテーマファイルのパスを出力するテンプレートタグってないのかな。。

bloginfo('template_directory') だと、「http://〜/wp-content/themes/〜」
になるのだけど、
WPインストールディレクトリ基準(/wp-content/themes/〜)で取得したい。


テーマファイル内の、function.phpに、

function theme_url () {
echo str_replace(get_bloginfo('url'), "", get_bloginfo('template_directory'));
}

というのを追加して、
テンプレート内で、

<?php theme_url(); ?>

として取得。

任意の内容のxmlを出力させる。

テーマのindex.php

<?php
// /?xml=onでアクセスすると以下の処理。
if ( isset( $_GET["xml"]) == "on" ) {

header('Content-Type: text/xml; charset='.get_option('blog_charset'), true);
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

//query_postsで指定があればなんか指定。
query_posts('');
if (have_posts()) : while (have_posts()) : the_post();  ?>

〜書き出したいxmlの内容を書く〜

<?
endwhile; else: endif;

} else { ?>

〜 いつものindex 〜

<?php } ?>

とかして、/?xml=onでアクセスすればいいんじゃないのーという話。

カスタムフィールドに登録した画像のサムネールやらを取得する。

WPってアップロードした時に、管理画面の設定>メディアで指定したサイズで
・サムネイル
・中サイズ
・大サイズ
それぞれの画像が自動的に生成される。

それを利用してカスタムフィールドで登録した画像の生成されたリサイズ画像を取得する。
より個別具体的にいうと、カスタムフィールドで画像登録してlightbox的な事したいんだけど、という時の対応。
これでできたけどスマートかどうかはわからない。

前提

  • カスタムフィールドの数は10コとする(仮に)。
  • フィールド名はimage01〜image10。
  • フィールド内にはオリジナル画像のURLが入力される。

やってる事

  1. カスタムフィールドの画像(値/URL)とその個数を取得
  2. 表示しているエントリーに紐付けられてる画像(URL)とその個数を取得 ※ギャラリーで表示される画像群
  3. 1と2の値(URL)を比較して、カスタムフィールドに登録した画像のattachmentIDを取得する
  4. wp_get_attachment_image( or wp_get_attachment_image_src)にattachmentIDとサムネールの種類をわたして画像ゲット。


※コレ、訳あって画像登録のフロントエンドをカスタムフィールドにしてるけど、
並び替えの手軽さや管理しやすさ(一括アップロードなど)を考えるとギャラリーで管理するのが良いですね。

<?php  if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
//1. カスタムフィールドの値を取得する。
for($i=1;$i<=10;$i++) { //前提でフィールド最大10としたので10回繰り返し
	$numb=sprintf("%02d",$i); //$iの数を1桁の場合、0(n)と2桁に
	$custom = post_custom('image'.$numb.''); //image0(n)を取り出して$customに格納
	if($custom) { //custom
  		$image_list[] = $custom;
	} else {
		break;
		//値がないならbreakしてるけど、image01とimage03は値あり、image02は空欄みたいな事があるなら、breakしないほうがいいか。
	}
}

//$image_listの数を取得
$image_list_count = count($image_list);


//2. このポストに関連付けされた画像ファイルを取得。
$attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order',  'order' => 'ASC'));
//↑このエントリーの編集画面のメディアアップロードダイアログ内、ギャラリー部分に表示される画像群を取得。
//'orderby' => 'menu_order'はギャラリー部分で指定した表示順。

//確認用:print_r($attachments); 
//$attachmentsの中身は
//[attachmentID][post_author、その他いろいろ]みたいな感じになってる。


//3. 1と2の値(URL)を比較して、カスタムフィールドに登録した画像のattachmentIDを取得する
for ($i=0; $i<=$image_list_count; $i++) {
	
	foreach ( $attachments as $key => $value ) { //$attachmentを展開する
		if ($attachments[$key]->guid == $image_list[$i] ) { //attachmentsの画像URLとカスタムフィールドの値を比較、一致したら以下。

			//4. wp_get_attachment_image( or wp_get_attachment_image_src)にattachmentIDとサムネールの種類をわたして画像ゲット。
			$large_url =  wp_get_attachment_image_src($key,'large'); //attachmentIDが$keyの大サイズ(large)の画像の値を取得、large以外は、thumbnail,medium,full。

			echo "<a href=\"".$large_url[0]."\">";//[0]がurl、[1]が幅、[2]が高さ、[3]はなんだろ。
			echo wp_get_attachment_image($key,'thumbnail');//attachmentIDが$keyのサムネイルサイズ(thumbnail)の画像の表示タグ(<img>)を取得
			echo "</a>";
		}
	}
}

// 繰り返し用に配列削除しとく - 2010.07.01 追加 - 
unset($attachments);
unset($image_list);

?>
<?php endwhile; endif: ?>

※バックスラッシュが「\」マークになってる。。