Last active
August 29, 2015 14:20
-
-
Save tecking/401315023db840d33025 to your computer and use it in GitHub Desktop.
パンくずリストに構造化データを追記する baserCMS 用独自ヘルパー
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 = '»', $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