「関数リファレンス/BcBaser blogPosts」の版間の差分
提供: baserCMS公式ガイド
(5人の利用者による、間の7版が非表示) | |||
行1: | 行1: | ||
## 説明 | ## 説明 | ||
− | + | ブログ記事一覧出力 | |
## 使い方 | ## 使い方 | ||
行8: | 行8: | ||
## パラメータ | ## パラメータ | ||
− | $contentsName | + | (文字列)$contentsName |
− | : | + | : 管理システムで指定したコンテンツ名 |
− | : 初期値 | + | : 初期値 nul :全てのブログが取得対象に |
− | $num | + | (数値)$num |
− | + | ||
: 記事件数 | : 記事件数 | ||
− | : | + | : 初期値:5 |
− | + | (array)$options | |
− | + | : オプション | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | $options | + | |
− | : | + | |
- 初期値:array() | - 初期値:array() | ||
− | - 'category' | + | - 'category':カテゴリで絞り込む場合にアルファベットのカテゴリ名指定(初期値 : null) |
− | - 'tag' | + | - 'tag':タグで絞り込む場合にタグ名を指定(初期値 : null) |
− | - 'year' | + | - 'year':年で絞り込む場合に年を指定(初期値 : null) |
− | - 'month' | + | - 'month':月で絞り込む場合に月を指定(初期値 : null) |
− | - 'day' | + | - 'day':日で絞り込む場合に日を指定(初期値 : null) |
− | - 'id' | + | - 'id':id で絞り込む場合に id を指定(初期値 : null) |
− | - 'keyword' | + | - 'keyword':キーワードで絞り込む場合にキーワードを指定(初期値 : null) |
− | - 'template' | + | - 'template':読み込むテンプレート名を指定する場合にテンプレート名を指定(初期値 : null) |
+ | - 'contentsTemplate':どのブログのテンプレート名を利用するか''ブログ名''(news等)を指定(初期値 : null)※3.0.10で実装。指定方法が変更する可能性アリ | ||
+ | - `direction` : 並び順の方向を指定 [昇順:ASC or 降順:DESC](初期値 : null) | ||
+ | - `sort` : 並び替えの基準となるフィールドを指定(初期値 : null) | ||
+ | - `page` : ページ数を指定(初期値 : null) | ||
## 戻り値 | ## 戻り値 | ||
− | + | なし | |
− | + | ||
## 用例 | ## 用例 | ||
行73: | 行66: | ||
<li><span class="date">2014.11.2</span><span class="title"><a href="/news/archives/1">ホームページをオープンしました。</a></span></li> | <li><span class="date">2014.11.2</span><span class="title"><a href="/news/archives/1">ホームページをオープンしました。</a></span></li> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | ####コード | ||
+ | ブログの詳細記事表示中に、同じカテゴリの記事を関連記事として表示させたい場合 | ||
+ | <syntaxhighlight lang="php"> | ||
+ | <?php $this->BcBaser->blogPosts('news', 3, array('category'=>$post['BlogCategory']['name'])); ?> | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | ####コード:全てのブログから最新記事を取得する | ||
+ | <syntaxhighlight lang="php"> | ||
+ | <?php | ||
+ | //全ブログから10件記事を取得 | ||
+ | $this->BcBaser->blogPosts(null, 10, array( | ||
+ | 'contentsTemplate' => 'news' //どのブログ(post.php)を使うか | ||
+ | )); | ||
+ | ?> | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
## 注 | ## 注 | ||
行84: | 行96: | ||
##類似の関数 | ##類似の関数 | ||
− | [[Category: | + | [[Category:関数リファレンス]] |
2016年7月11日 (月) 21:57時点における最新版
目次
説明
ブログ記事一覧出力
使い方
$this->BcBaser->blogPosts( $contentsName, [$num] , [$options] );
パラメータ
- (文字列)$contentsName
- 管理システムで指定したコンテンツ名
- 初期値 nul :全てのブログが取得対象に
- (数値)$num
- 記事件数
- 初期値:5
- (array)$options
-
オプション
- 初期値:array()
- 'category':カテゴリで絞り込む場合にアルファベットのカテゴリ名指定(初期値 : null)
- 'tag':タグで絞り込む場合にタグ名を指定(初期値 : null)
- 'year':年で絞り込む場合に年を指定(初期値 : null)
- 'month':月で絞り込む場合に月を指定(初期値 : null)
- 'day':日で絞り込む場合に日を指定(初期値 : null)
- 'id':id で絞り込む場合に id を指定(初期値 : null)
- 'keyword':キーワードで絞り込む場合にキーワードを指定(初期値 : null)
- 'template':読み込むテンプレート名を指定する場合にテンプレート名を指定(初期値 : null)
- 'contentsTemplate':どのブログのテンプレート名を利用するかブログ名(news等)を指定(初期値 : null)※3.0.10で実装。指定方法が変更する可能性アリ
direction
: 並び順の方向を指定 [昇順:ASC or 降順:DESC](初期値 : null)sort
: 並び替えの基準となるフィールドを指定(初期値 : null)page
: ページ数を指定(初期値 : null)
戻り値
なし
用例
基本
コード
<?php $this->BcBaser->blogPosts('news', 5); ?>
出力
<ul> <li><span class="date">2014.11.2</span><span class="title"><a href="/news/archives/5">ホームページをオープンしました。</a></span></li> <li><span class="date">2014.11.2</span><span class="title"><a href="/news/archives/4">新商品を販売を開始しました。</a></span></li> <li><span class="date">2014.11.2</span><span class="title"><a href="/news/archives/3">ホームページをオープンしました。</a></span></li> <li><span class="date">2014.11.2</span><span class="title"><a href="/news/archives/2">新商品を販売を開始しました。</a></span></li> <li><span class="date">2014.11.2</span><span class="title"><a href="/news/archives/1">ホームページをオープンしました。</a></span></li> </ul>
応用
コード
<?php $this->BcBaser->blogPosts('news', 3, array('category'=>'release', 'year'=>'2014', 'template'=>'posts')); ?>
出力
<li><span class="date">2014.11.2</span><span class="title"><a href="/news/archives/3">ホームページをオープンしました。</a></span></li> <li><span class="date">2014.11.2</span><span class="title"><a href="/news/archives/2">新商品を販売を開始しました。</a></span></li> <li><span class="date">2014.11.2</span><span class="title"><a href="/news/archives/1">ホームページをオープンしました。</a></span></li>
コード
ブログの詳細記事表示中に、同じカテゴリの記事を関連記事として表示させたい場合
<?php $this->BcBaser->blogPosts('news', 3, array('category'=>$post['BlogCategory']['name'])); ?>
コード:全てのブログから最新記事を取得する
<?php //全ブログから10件記事を取得 $this->BcBaser->blogPosts(null, 10, array( 'contentsTemplate' => 'news' //どのブログ(post.php)を使うか )); ?>