Warning: Undefined array key 0 in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 406

Warning: Attempt to read property "parent" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 407

Warning: Attempt to read property "term_id" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 413

Warning: Attempt to read property "cat_name" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 413

【WordPress】マルチサイトでサイト毎に処理を条件分岐させる方法

wordpress

マルチサイトを運営していると、サイト毎に微妙にやりたい事も変わってきます。 例えば親サイトの検索は横断検索にしたいとか、カスタム投稿タイプの設定をサイト毎に別のものにしたいなどがあります。

テーマを完全に分けるのも一つの手段ですが、それほどの違いでなければサイト毎に条件分岐して処理を変えるのも手です。 WordPressにおいては「親サイトと子サイト」または「ブログID」で条件分岐させることができます。

親サイトと子サイトで条件分岐

親サイトと子サイトで条件分岐させたい場合、is_main_siteで判定できます。

  // 親サイトでの処理

  // 子サイトでの処理

ブログIDで条件分岐

ブログIDで条件分岐させたい場合、ブログIDを指定して処理を記述することができます。

ブログIDは[サイトネットワーク管理]→[サイト]→[IDを知りたいサイト]をクリックし、URL末尾の「ID=n」に表示されているものです。

f ( get_current_blog_id() == 1 ) {
  //ブログIDが1のサイトの処理
}

サイト毎の使用テンプレートファイルの振り分けなんかもよくやります。

witch(get_current_blog_id()){
  case 1:
    get_template_part('frontpageA');
    break; 
  default: 
    get_template_part('frontpageB');
}

Warning: Undefined variable $category in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/content.php on line 79

Warning: Attempt to read property "name" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/content.php on line 79

の記事

eyecatch

要素と属性

eyecatch

CSSで指定したスタイルをHTMLに読み込む方法

eyecatch

body要素内をマークアップする流れ

eyecatch

WordPressに独自テーブルを追加する方法

eyecatch

CSSでアニメーションを設定する

eyecatch

投稿やカテゴリを任意の順番に並び替えるプラグイン


Warning: Undefined variable $category in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/content.php on line 84

Warning: Attempt to read property "count" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/content.php on line 84
HOME