Show category with images in homepage Magento2 -


show category images in homepage magento2

http://ibnab.com/en/blog/magento-2/magento-2-frontend-how-to-call-category-collection-on-home-page

this article working fine need show category image.how fetch category images also

i using $category->getimageurl();

but not working

i able show on homepage combining tutorial , r t's answer. because didn't have _objectmanager (and page kicking error when tried r t's code) working on page, included category model in block file (categoriscollection.php)

protected $_categoryhelper; protected $categoryflatconfig; protected $topmenu; protected $categoryview;  public function __construct(     \magento\framework\view\element\template\context $context,     \magento\catalog\helper\category $categoryhelper,     \magento\catalog\model\indexer\category\flat\state $categoryflatstate,     \magento\theme\block\html\topmenu $topmenu,     \magento\catalog\model\category $categoryview ) {      $this->_categoryhelper = $categoryhelper;     $this->categoryflatconfig = $categoryflatstate;     $this->topmenu = $topmenu;     $this->categoryview = $categoryview;     parent::__construct($context); } 

i added method call in phtml @ bottom of block file.

    public function getcategoryview() {     return $this->categoryview; } 

in phtml (storecategories.phtml) changed code work this.

<?php $categories = $this->getstorecategories(true,false,true); $categoryhelper = $this->getcategoryhelper(); ?> <ul> <?php     foreach($categories $category):         if (!$category->getisactive()) {             continue;         } ?>     <li><a href="<?php echo $categoryhelper->getcategoryurl($category) ?>"> <?php     $catid = $category->getid();     $categoryagain = $this->getcategoryview()->load($catid);     $_outputhelper = $this->helper('magento\catalog\helper\output');     $_imghtml   = '';     if ($_imgurl = $categoryagain->getimageurl()) {         $_imghtml = '<img src="' . $_imgurl . '" />';         $_imghtml = $_outputhelper->categoryattribute($categoryagain, $_imghtml, 'image');         /* @escapenotverified */          echo $_imghtml;     } ?>     <?php echo $category->getname() ?></a></li>     <?php endforeach; ?> </ul> 

and added new call di.xml

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="../../../../../../lib/internal/magento/framework/objectmanager/etc/config.xsd"> <type name="ibnab\categoriesside\block\categoriscollection">     <arguments>         <argument name="deleteorderaction" xsi:type="array">             <item name="context" xsi:type="string">\magento\framework\view\element\template\context</item>             <item name="helper" xsi:type="string">\magento\catalog\helper\category</item>             <item name="flatstate" xsi:type="string">\magento\catalog\model\indexer\category\flat\state</item>             <item name="menu" xsi:type="string">\magento\theme\block\html\topmenu</item>             <item name="categoryview" xsi:type="string">\magento\catalog\model\category</item>         </argument>     </arguments> </type> 


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -