wptouchのdefault以外のテンプレートを作成する方法  2011年5月10日

ついでに、wptouchに独自のテンプレートを適用する方法

wptouchのプラグイン内を直接編集してもいいのだけれど、アップデートの時などに上書きされてしまうと危ないので、PC用のテーマのところにもう一つテーマを作って利用するようにする方法。

独自にプラグインを作成しプラグインファイル内に、下記のように書いておき、「プラグイン名」のところに、PC用テーマを作成したフォルダ名を記入すると、そっちのテーマを読んでくれる。

if(!is_admin()){
    global $wptouch_plugin;

	function hip_iphone_get_stylesheet( $stylesheet ) {
		if (bnc_is_iphone()) {
			return "プラグイン名";
		} else {
			return $stylesheet;
		}
	}
    add_filter( 'stylesheet', 'hip_iphone_get_stylesheet' , 20);

    function hip_iphone_get_template( $template ) {
    	if (bnc_is_iphone()) {
    	   return "プラグイン名";
    	} else {
    	   return $template;
    	}
    }
    add_filter( 'template', "hip_iphone_get_template" , 20 );

    function hip_iphone_theme_root( $path ) {
    	if (bnc_is_iphone()) {
    	   return realpath(dirname(__FILE__) . '/../../themes');
    	} else {
    	   return $path;
    	}
    }
    add_filter( 'theme_root', "hip_iphone_theme_root" , 20 );

    function hip_iphone_theme_root_uri( $uri ) {
    	if (bnc_is_iphone()) {
    	   return 'http://' . $_SERVER['SERVER_NAME'] . '/wp-content/themes';
    	} else {
    	   return $uri;
    	}
    }
    add_filter( 'theme_root_uri', "hip_iphone_theme_root_uri" , 20 );
}
このエントリをはてなブックマークに登録 このエントリをBuzzurlにブックマーク Yahoo!ブックマークに登録 このエントリをlivedoorクリップに登録 Deliciousにブックマーク

コメントを投稿