Skip to content

Instantly share code, notes, and snippets.

@tecking
Last active August 29, 2015 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tecking/401315023db840d33025 to your computer and use it in GitHub Desktop.
Save tecking/401315023db840d33025 to your computer and use it in GitHub Desktop.
パンくずリストに構造化データを追記する baserCMS 用独自ヘルパー
<?php
/**
* SDHelper パンくずリストに構造化データを追記するヘルパー
* テーマファイル内で $this->SD->foo() の記述で呼び出す
*/
class SDHelper extends AppHelper {
/**
* ヘルパー
*/
public $helpers = array('BcBaser', 'BcHtml');
/**
* パンくずリストの要素を追加する
* パラメータ, 返り値は $this->BcBaser->addCrumb() に準ずる
*/
public function addCrumb($name, $link = null, $options = array()) {
$options = array_merge(array(
'forceTitle' => true
), $options);
if (!empty($link)) {
$options['itemprop'] = 'url';
$this->BcHtml->addCrumb($this->BcHtml->tag('span', $name, array('itemprop' => 'title')), $link, $options);
return;
}
$this->BcHtml->addCrumb($name, $link, $options);
}
/**
* パンくずリストを出力する
* パラメータ, 返り値は $this->BcBaser->crumbs() に準ずる
*/
public function crumbs($separator = '&raquo;', $startText = false) {
$crumbs = $this->BcHtml->getStripCrumbs();
if (empty($crumbs)) {
return;
}
$out = array();
if ($startText) {
$out[] = $this->BcHtml->tag('span', $this->BcBaser->getLink($this->BcHtml->tag('span', $startText, array('itemprop' => 'title')), '/', array('itemprop' => 'url')), array('itemscope', 'itemtype' => 'http://data-vocabulary.org/Breadcrumb'));
}
foreach ($crumbs as $crumb) {
if (!empty($crumb[1])) {
$out[] = $this->BcHtml->tag('span', $this->BcBaser->getLink($crumb[0], $crumb[1], $crumb[2]), array('itemscope', 'itemtype' => 'http://data-vocabulary.org/Breadcrumb', 'itemprop' => 'child'));
} else {
$out[] = $crumb[0];
}
}
echo implode($separator, $out);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment