如何在 Magento 2 的 FishPig 中获取当前的 WordPress 类别?
How to get current WordPress category in FishPig in Magento 2?
获取视图中当前类别的最直接方法是什么?我注意到 Term class:
中有一个 getTerm 方法
public function getEntity()
{
return $this->getTerm();
}
/**
* Returns the current Wordpress category
* This is just a wrapper for getCurrentCategory()
*
* @return \FishPig\WordPress\Model\Term
*/
public function getTerm()
{
if (!$this->hasTerm()) {
$this->setTerm($this->_registry->registry(Term::ENTITY));
}
return $this->_getData('term');
}
但是,如果我尝试在模板中使用该方法(例如,默认的 post list wrapper.phtml 模板在布局中使用了 Term 块),它会抛出一个错误:
<?php echo $this->getTerm() ?>
Recoverable Error: Object of class FishPig\WordPress\Model\Term could
not be converted to string in
我可能只是遗漏了一些简单的东西,我们将不胜感激任何帮助。谢谢!
$term = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Framework\Registry')
->registry('wordpress_term');
获取视图中当前类别的最直接方法是什么?我注意到 Term class:
中有一个 getTerm 方法public function getEntity()
{
return $this->getTerm();
}
/**
* Returns the current Wordpress category
* This is just a wrapper for getCurrentCategory()
*
* @return \FishPig\WordPress\Model\Term
*/
public function getTerm()
{
if (!$this->hasTerm()) {
$this->setTerm($this->_registry->registry(Term::ENTITY));
}
return $this->_getData('term');
}
但是,如果我尝试在模板中使用该方法(例如,默认的 post list wrapper.phtml 模板在布局中使用了 Term 块),它会抛出一个错误:
<?php echo $this->getTerm() ?>
Recoverable Error: Object of class FishPig\WordPress\Model\Term could not be converted to string in
我可能只是遗漏了一些简单的东西,我们将不胜感激任何帮助。谢谢!
$term = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Framework\Registry')
->registry('wordpress_term');