個人用ツール

「ver4/関数リファレンス/BcBaser blogPosts」の版間の差分

提供: baserCMS公式ガイド

移動: 案内, 検索
 
 
(他の1人の利用者による、間の1版が非表示)
行6: 行6:
 
## 使い方
 
## 使い方
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
$this->BcBaser->blogPosts( $contentsName, [$num] , [$options] );
+
$this->BcBaser->blogPosts( $contentsName , $num , [$options] );
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
## パラメータ
 
## パラメータ
(文字列)$contentsName
+
(string | array) $contentsName
 
:  管理システムで指定したコンテンツ名
 
:  管理システムで指定したコンテンツ名
: 初期値 nul :全てのブログが取得対象に
+
: 初期値 nul  
 +
: 2階層目以降はURLで指定
  
(数値)$num
+
(int) $num
 
: 記事件数
 
: 記事件数
 
: 初期値:5
 
: 初期値:5
  
(array)$options
+
(array) $options
 
: オプション
 
: オプション
 
+
: 初期値:array()
    - 初期値:array()
+
:    - `category`:カテゴリで絞り込む場合にアルファベットのカテゴリ名指定(初期値 : null)
    - 'category':カテゴリで絞り込む場合にアルファベットのカテゴリ名指定(初期値 : null)
+
:    - `tag`:タグで絞り込む場合にタグ名を指定(初期値 : null)
    - 'tag':タグで絞り込む場合にタグ名を指定(初期値 : null)
+
:    - `year`:年で絞り込む場合に年を指定(初期値 : null)
    - 'year':年で絞り込む場合に年を指定(初期値 : null)
+
:    - `month`:月で絞り込む場合に月を指定(初期値 : null)
    - 'month':月で絞り込む場合に月を指定(初期値 : null)
+
:    - `day`:日で絞り込む場合に日を指定(初期値 : null)
    - 'day':日で絞り込む場合に日を指定(初期値 : null)
+
:    - `id`:id で絞り込む場合に id を指定(初期値 : null)
    - 'id':id で絞り込む場合に id を指定(初期値 : null)
+
:    - `keyword`:キーワードで絞り込む場合にキーワードを指定(初期値 : null)
    - 'keyword':キーワードで絞り込む場合にキーワードを指定(初期値 : null)
+
:    - `template`:読み込むテンプレート名を指定する場合にテンプレート名を指定(初期値 : null)
    - 'template':読み込むテンプレート名を指定する場合にテンプレート名を指定(初期値 : null)
+
:    - `contentsTemplate`:どのブログのテンプレート名を利用するか''ブログ名''(news等)を指定(初期値 : null)※3.0.10で実装。指定方法が変更する可能性アリ
    - 'contentsTemplate':どのブログのテンプレート名を利用するか''ブログ名''(news等)を指定(初期値 : null)※3.0.10で実装。指定方法が変更する可能性アリ
+
:    - `direction` : 並び順の方向を指定 [昇順:ASC or 降順:DESC](初期値 : null)
    - `direction` : 並び順の方向を指定 [昇順:ASC or 降順:DESC](初期値 : null)
+
:    - `sort` : 並び替えの基準となるフィールドを指定(初期値 : null)
    - `sort` : 並び替えの基準となるフィールドを指定(初期値 : null)
+
:    - `page` : ページ数を指定(初期値 : null)
    - `page` : ページ数を指定(初期値 : null)
+
  
 
## 戻り値
 
## 戻り値

2016年11月4日 (金) 20:15時点における最新版

[このコンテンツは内容調整中です]

説明

ブログ記事一覧出力

使い方

$this->BcBaser->blogPosts( $contentsName , $num , [$options] );

パラメータ

(string | array) $contentsName
管理システムで指定したコンテンツ名
初期値 nul
2階層目以降はURLで指定
(int) $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)を使うか
));
?>

変更履歴

ソースファイル

関連資料

類似の関数