メインコンテンツまでスキップ
Version: Fegg 5.x

JsonLd::graph

複数の項目を1つのscriptにまとめます

説明​

public static array JsonLd::graph( array ...$items )

項目を渡した順に入れたarray('@context' => 'https://schema.org', '@graph' => array(...))を返します。各項目の@contextは取り除き(graphに1つだけ入ります)、空の項目は出力しません。

引数​

名前データ型デフォルト備考
...$itemsarrayほかの関数の戻り値、または@typeを持つ独自の配列

例​

htdocs/_fegg/site/src/Controller/Index.php
use Fegg\Tool\JsonLd;

$siteName = $this->config['site_info']['name'];
$this->setSiteinfo('json_ld', JsonLd::graph(
JsonLd::website($siteName, '/'),
JsonLd::organization($siteName, '/')
));

独自の項目は、schema.orgの型を配列で書きます。

Controller
$this->setSiteinfo('json_ld', JsonLd::graph(
JsonLd::breadcrumb(array('ホーム' => '/', '店舗' => '/shops/', $shop['name'] => '')),
array(
'@type' => 'Store',
'name' => $shop['name'],
'telephone' => $shop['tel'],
'url' => feggAbsoluteUrl('/shops/' . $shop['shop_id'] . '/'),
)
));

独自の配列はそのまま書き出すので、URLはfeggAbsoluteUrl()で自分で絶対URLにしてください。