1

we have used this link and install module step by steps http://www.ibnab.com/en/blog/magento-2/magento-2-frontend-how-to-call-category-collection-on-home-page

My module is installed and showing up in config.php but we able to get any thing on home page, Please let me know.

2

Please follow below steps to show all products and categories on homepage:

  1. Login to Magento 2 Admin page and go to Content->Pages.

  2. Select the Edit option from the Home Page.

  3. Click the Content tab from Left Side navigation section.

  4. Remove the existing content from that page and click the widget icon from the editor.

  5. Select the widget type as ‘Catalog Products List’ and enter the basic information. In the bottom, you can see the conditions to add. Select the option ‘Category’ and select the category you want to display on the home page and click “Insert Widget” button.

That’s it. Save the page and clear the cache.

Now you will be able to see the products of the category on the Home Page.

If you want to screenshot then visit the link: http://www.dckap.com/blog/magento-2/

  • are these steps for showing products in the home page or showing the category collection images in home page using the mentioned plugin link? Since that is the question! – Sushivam Feb 28 '17 at 12:36
0

create a simple module:

  • 1.Get store category list in a function.

    • 1.1 Get child category list(if any) in another function

Note: this you can do in Block(example.php).

  • 2.Call the store category function in phtml file.

Example code:

app/code/vendorname/Modulename/Block/Example.php

namespace vendorname\Modulename\Block;

use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\Catalog\Model\ResourceModel\Product;
use Magento\Framework\View\Element\Template;
class Example extends \Magento\Framework\View\Element\Template
{
    protected $_categoryHelper;
    protected $categoryFlatConfig;
    protected $topMenu;
    /**
     * @var \Magento\Framework\Registry
     */
    protected $_coreRegistry;
    /**
     * @param \Magento\Framework\View\Element\Template\Context $context
     * @param \Magento\Catalog\Helper\Category $categoryHelper
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Catalog\Helper\Category $categoryHelper,
        \Magento\Framework\Registry $registry,
        \Magento\Catalog\Model\Indexer\Category\Flat\State $categoryFlatState,
        \Magento\Theme\Block\Html\Topmenu $topMenu
       // \Magento\Review\Model\Review $reviewFactory
    ) {
        $this->_categoryHelper = $categoryHelper;
        $this->_coreRegistry = $registry;
        $this->categoryFlatConfig = $categoryFlatState;
        $this->topMenu = $topMenu;
       // $this->_objectReview = $reviewFactory;
        parent::__construct($context);
    }
    /**
     * Return categories helper
     */
    public function getCategoryHelper()
    {
        return $this->_categoryHelper;
    }

    public function getCurrentCategory(){
        return $this->_coreRegistry->registry('current_category');
    }
public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
    {
        return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);
    }
    /**
     * Retrieve child store categories
     *
     */
    public function getChildCategories($category)
    {
        if ($this->categoryFlatConfig->isFlatEnabled() && $category->getUseFlatResource()) {
            $subcategories = (array)$category->getChildrenNodes();
        } else {
            $subcategories = $category->getChildren();
        }
        return $subcategories;
    }
}

in phtml file call the function like

<?php
$categories = $this->getStoreCategories(true,false,true);
$categoryHelper = $this->getCategoryHelper();


foreach($categories as $category):
     // do whatever you want to.

     }
?>
0

it's work but I think you need change default design of the home page to the 2columns left. we used this technique in GitHub. but if you are dev mag2 you can use the base code and customize

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.