LoginSignup
1
0

More than 5 years have passed since last update.

【baserCMS】お問い合わせページの分岐

Last updated at Posted at 2019-03-05

お問い合わせページのスラッグとして「contact」を使うことが多いと思うんですが、
お問い合わせページだけを分岐する為に、固定ページの分岐と同じように

<?php if (strtolower($this->BcBaser->getContentsName()) === 'contact'): ?>
〜contactページだけに表示したいコンテンツ〜
<?php endif; ?>

このように書いても効きません。
フォームページを分岐したいときは

$currentContent = $this->BcBaser->getCurrentContent(); // 現在のコンテンツ情報を取得
var_dump($currentContent);

を使ってname値、plugin値、type値を用いて分岐させた方が、
フォームのURLが変わったときにも対応できるのでおすすめです。

書き方としては

<?php
        $currentContent = $this->BcBaser->getCurrentContent(); 
        if($currentContent['name'] === "contact"){
       echo 'contactページだけに表示したいコンテンツ';
      }; ?>

こんな感じ。
逆にcontact以外のページに表記したいときは

<?php
        $currentContent = $this->BcBaser->getCurrentContent(); 
        if($currentContent['name'] == "contact"){
       echo 'contactページ以外に表示したいコンテンツ';
      }; ?>

という感じになります。

ちなみにelseifを使いたい場合は

<?php if ($this->BcBaser->isBlogSingle()): ?>
'ブログの詳細ページで表示したいコンテンツ'
<?php elseif($this->name == 'Mail'): ?>
'contactページだけに表示したいコンテンツ'
<?php endif; ?>

という感じで「Mail」を指定します。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0