「ver4/関数リファレンス/title」の版間の差分
提供: baserCMS公式ガイド
(ページの作成:「## 説明 タイトルタグを出力する ## 使い方 <syntaxhighlight lang="php"> $this->BcBaser->title($separator , $categoryTitleOn ); </syntaxhighlight> ## パ...」) |
|||
(3人の利用者による、間の13版が非表示) | |||
行1: | 行1: | ||
## 説明 | ## 説明 | ||
− | + | メタタグのtitleを出力する。<br> | |
+ | ページタイトルとして文字列のみ出力したい場合は、<a href="http://wiki.basercms.net/ver4/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/contentsTitle">contentsTitle()</a>を使用する。 | ||
## 使い方 | ## 使い方 | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | $this->BcBaser->title($separator , $ | + | <?php $this->BcBaser->title( [$separator] , [$options] ); ?> |
</syntaxhighlight> | </syntaxhighlight> | ||
## パラメーター | ## パラメーター | ||
− | + | (string) $separator | |
− | + | : 階層の区切り文字を指定する。 | |
+ | : - 初期値 = '|' | ||
+ | |||
+ | (array) $options | ||
+ | :`categoryTitleOn` : カテゴリを表示するかを boolean で指定。falseで表示しない。(初期値 = null) | ||
+ | :`tag` : タグが記述されていた場合、どのように扱うかを boolean で指定。trueでエンコードして出力、falseで除去する。(初期値 = true) | ||
+ | :`allowableTags` : tagがfalseだった場合、**除去しないタグ**をPHPの[strip_tags](http://php.net/manual/ja/function.strip-tags.php)の書式で指定。(初期値 = (空)) | ||
− | |||
## 用例 | ## 用例 | ||
### 基本 | ### 基本 | ||
+ | タイトルタグを出力する。 | ||
####コード | ####コード | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | <?php $this->BcBaser->title( | + | <?php $this->BcBaser->title() ?> |
</syntaxhighlight> | </syntaxhighlight> | ||
####出力 | ####出力 | ||
− | + | <syntaxhighlight lang="html5"> | |
− | <syntaxhighlight lang=" | + | <title>コンテンツタイトル | カテゴリ| サイト名</title> |
− | <title> | + | |
</syntaxhighlight> | </syntaxhighlight> | ||
### 応用 | ### 応用 | ||
+ | 階層を:区切りで表示、カテゴリーを表示しない、タグを除去(<srtong>は除去しない)でタイトルタグを出力する。<br> | ||
+ | 例)タイトルが**<em>サービス</em><strong>1</strong>**、カテゴリーが**サービス**、サイト名が**baserCMS inc.**だった場合 | ||
####コード | ####コード | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | + | <?php | |
+ | $args = array( | ||
+ | 'categoryTitleOn' => false, | ||
+ | 'tag' => false, | ||
+ | 'allowableTags' => '<strong>' | ||
+ | ); | ||
+ | $this->BcBaser->title(' : ', $args); | ||
+ | ?> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
####出力 | ####出力 | ||
− | + | <syntaxhighlight lang="html5"> | |
− | + | <title>サービス<strong>1</strong> : baserCMS inc.</title> | |
− | + | </syntaxhighlight> | |
− | + | ||
− | + | ||
− | + | ||
− | ## | + | ##類似の関数 |
− | [[ | + | - [getContentsTitle](/ver4/関数リファレンス/getContentsTitle) - コンテンツタイトルを取得する |
+ | - [contentsTitle](/ver4/関数リファレンス/contentsTitle) - コンテンツのタイトルを出力する | ||
+ | - [getTitle](/ver4/関数リファレンス/getTitle) - タイトルタグを取得する |
2018年12月13日 (木) 00:56時点における最新版
説明
メタタグのtitleを出力する。
ページタイトルとして文字列のみ出力したい場合は、contentsTitle()を使用する。
使い方
<?php $this->BcBaser->title( [$separator] , [$options] ); ?>
パラメーター
- (string) $separator
- 階層の区切り文字を指定する。
- - 初期値 = '|'
(array) $options
categoryTitleOn
: カテゴリを表示するかを boolean で指定。falseで表示しない。(初期値 = null)tag
: タグが記述されていた場合、どのように扱うかを boolean で指定。trueでエンコードして出力、falseで除去する。(初期値 = true)allowableTags
: tagがfalseだった場合、除去しないタグをPHPのstrip_tagsの書式で指定。(初期値 = (空))
用例
基本
タイトルタグを出力する。
コード
<?php $this->BcBaser->title() ?>
出力
<title>コンテンツタイトル | カテゴリ| サイト名</title>
応用
階層を:区切りで表示、カテゴリーを表示しない、タグを除去(<srtong>は除去しない)でタイトルタグを出力する。
例)タイトルが<em>サービス</em><strong>1</strong>、カテゴリーがサービス、サイト名がbaserCMS inc.だった場合
コード
<?php $args = array( 'categoryTitleOn' => false, 'tag' => false, 'allowableTags' => '<strong>' ); $this->BcBaser->title(' : ', $args); ?>
出力
<title>サービス<strong>1</strong> : baserCMS inc.</title>
類似の関数
- getContentsTitle - コンテンツタイトルを取得する
- contentsTitle - コンテンツのタイトルを出力する
- getTitle - タイトルタグを取得する