• 解決済 niconicomafmaf

    (@niconicomafmaf)


    マルチサイトを作成しています。
    スマホ用をwptouchを利用してテーマを分けたいのですが、

    http://ameblo.jp/buyship/entry-11185928711.html
    こちらを参考に、wptouch.phpを

    function get_stylesheet( $stylesheet ) {
    if ($this->applemobile && $this->desired_view == ‘mobile’) {
    return ‘default’;
    } else {
    return $stylesheet;
    }
    }

    function get_template( $template ) {
    $this->bnc_filter_iphone();
    if ($this->applemobile && $this->desired_view === ‘mobile’) {
    return ‘default’;
    } else {
    return $template;
    }
    }

    を下記へ書き換えました。

    function get_stylesheet( $stylesheet ) {
    $mysiteid = $GLOBALS[‘blog_id’];  //ブログIDを$mysiteidに代入
    if ($mysiteid == 1) {  //もしブログIDが1だったら
    if ($this->applemobile && $this->desired_view == ‘mobile’) {
    return ‘corp’;  //ここは新たにコピーしたブログ1用のテーマの名前
    } else {
    return $stylesheet;
    }
    } elseif ($mysiteid == 2) {  //そうでなくて、ブログIDが2だったら
    if ($this->applemobile && $this->desired_view == ‘mobile’) {
    return ‘portal’;  //ここも新たにコピーしたブログ2用のテーマの名前
    } else {
    return $stylesheet;
    }
    }
    }

    //こちらも同様に

    function get_template( $template ) {
    $this->bnc_filter_iphone();
    $mysiteid = $GLOBALS[‘blog_id’];  //ブログIDを$mysiteidに代入
    if ($mysiteid == 1) {  //もしブログIDが1だったら
    if ($this->applemobile && $this->desired_view === ‘mobile’) {
    return ‘corp’;  //ここは新たにコピーしたブログ1用のテーマの名前
    } else {
    return $template;
    }
    } elseif ($mysiteid == 2) {  //そうでなくて、ブログIDが2だったら
    if ($this->applemobile && $this->desired_view === ‘mobile’) {
    return ‘portal’;  //ここも新たにコピーしたブログ2用のテーマの名前
    } else {
    return $template;
    }
    }
    }

    しかし、PC版スマホ版ともに真っ白になってしまいます。
    なにか、書き方がまずいでしょうか。

    PHPがわからず、困っています。
    どうぞ、宜しくお願い致します。

3件の返信を表示中 - 1 - 3件目 (全3件中)
  • おそらく、使用環境によって条件式に漏れがあり、値が不定になっているのではないかと思います。
    PHPの話ではなく、論理的な話で不都合がありそうです。
    上の条件を整理すると以下になります。

    1. $this->applemobile && $this->desired_view === ‘mobile’ が真の時
    • $mysiteid == 1ならば 返却値’corp’;
    • $mysiteid == 2ならば 返却値’portal’;
    • その他 返却値の記述なし
    • $this->applemobile && $this->desired_view === ‘mobile’ が偽の時
    • 返却値 $template

      まずはどの条件となっているのか、変数を一つ一つ表示させてみてはいかがでしょうか?

    コードの例示をしようと思って、よく見てたらfunction get_template( $template )の
    if ($this->applemobile && $this->desired_view === ‘mobile’) { は
    ‘=’ が一つ多いようです。
    この部分を修正しても症状が改善しないようならば、変数(特に$mysiteid)をご確認ください。

    私ならこうすると思ったコードは以下です。

    if ( $this->applemobile && $this->desired_view == 'mobile' ) {
    	switch ( $mysiteid ) :
    	case  1: return 'corp';	        //もしブログIDが1だったら新たにコピーしたブログ1用のテーマの名前
    	case  2: return 'portal';	//もしブログIDが2だったら新たにコピーしたブログ2用のテーマの名前
            default: return 'default';
    	endswitch;
    } else {
            return $stylesheet;
    }

    トピック投稿者 niconicomafmaf

    (@niconicomafmaf)

    shirakobato様

    shirakobato様がこうすると思ったコードで上手くいきました。
    大変たすかりました!
    ありがとうございます。

3件の返信を表示中 - 1 - 3件目 (全3件中)
  • トピック「wptouchでマルチサイトのテーマ反映」には新たに返信することはできません。