8
0

More than 5 years have passed since last update.

【baserCMS:初心者向け】ページごとにヘッダーなどの読み込みを分岐させる

Last updated at Posted at 2018-10-25

読み込みの分岐

例えばページによってヘッダーやフッターを切り分けたい時があると思います。
下層ページはヘッダーのデザインが違うとかメイン画像サイズが変わるとかメニューが変わるとか
そういう時に使えるタグです。
「"About"というスラッグのページだけはabout_header.phpを読み込む。」
「"Service"というスラッグのページだけはservice_header.phpを読み込む。」
「それ以外のページは共通でheader.phpを読み込む。」
といった感じになります。

<?php if($this->BcBaser->getContentsName() === 'About'): ?>
    <?php $this->BcBaser->element('about_header') ?>
<?php elseif($this->BcBaser->getContentsName() === 'Service'): ?>
    <?php $this->BcBaser->element('service_header') ?>
<?php else: ?>
    <?php $this->BcBaser->element('header') ?>
<?php endif ?>

トップページだけに表示したい時はこんな感じ。

<?php if($this->BcBaser->isHome()): ?>
<!-- トップページのみに出力する内容 -->
<?php endif ?>

ちなみに記事の詳細ページのみ分岐したい時はこうなります。

<?php if ($this->BcBaser->isBlogSingle()): ?>
    <?php $this->BcBaser->element('single_header') ?>
<?php else: ?>
    <?php $this->BcBaser->element('header') ?>
<?php endif; ?>

あと〇〇ページじゃない時!とか

<?php if (strtolower($this->BcBaser->getContentsName(true)) !== 'work'): ?>
<?php endif; ?>

複数ページをまとめて指定だとこんな感じですね。(スラッグがpolicyページかfaqページじゃない時)

<?php
$slug = strtolower($this->BcBaser->getContentsName(true));
if ($slug !== 'policy' && $slug !== 'faq'): ?>
〜コンテンツ〜
<?php endif; ?> 
8
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
8
0