個人用ツール

ver4/関数リファレンス/getPostImg

提供: baserCMS公式ガイド

移動: 案内, 検索

説明

記事中の画像を取得する

使い方

$this->Blog->getPostImg( [$post] , [$options]);

パラメータ

(array) $post
ブログ記事
(array) $options
オプション
初期値 : array()
- num : 何枚目の画像か順番を指定(初期値 : 1)
- link : 詳細ページへのリンクをつけるかどうか(初期値 : true)
- alt : ALT属性(初期値 : ブログ記事のタイトル)

戻り値

(string)
画像タグ、または、リンク付画像タグ

用例

以下のようなブログ記事の場合:

  • ブログのコンテンツ名が "news"
  • 記事NOが 1
  • 記事タイトルが "sample-post-title"
  • 1枚目に<img src="sample1.jpg">、2枚目に<img src="sample2.jpg">を含む

基本

コード

<?php $this->Blog->getPostImg($post, ['num' => 1]); ?>

出力

'<a href="/news/archives/1"><img src="/img/sample1.jpg" alt="sample-post-title"/></a>'

応用

コード

<?php $this->Blog->getPostImg($post, ['num' => 2, 'link' => false, 'alt' => 'sample-alt']); ?>

出力

'<img src="/img/sample2.jpg" alt="sample-alt"/>'