カテゴリ テンプレート (view.phtml) の外部から現在のカテゴリ イメージを取得するにはどうすればよいですか? たとえば、header.phtml または footer.phtml から取得したい場合。
view.phtml からコードをコピーしてみました:
<?php
$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p>';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>
しかし、ページをリロードするときにこのエラーが発生します: 致命的なエラー: 非オブジェクトでのメンバー関数 getImageUrl() への呼び出し