menu

Magento get current category details


Magento get current category details in 1.x and 2.x both version: Here in this tutorial, we are going to cover all details about the current category such as category name, category id, category url etc. We will explain how to get details in Magento 1 and Magneto 2. Here are the things which we will cover in this tutorial.

  • Id
  • Name
  • Url
  • Description
  • Level
  • Image Url
  • Thumbnail Image Url
  • Product Collection

Magento get current category Details | Magento 2

There are followings conditions to get category details –
1 – You want to get current selected category detail.
2 – Or You want load category detail by Category Id.

Let us start with above both conditions –


Get Details in Magento 2

In Magento 2 you can get the details simly as below-


Magento 2 get current category Id

You can use object managet to get the current category id in Magento 2.

Get current Category Id In Magento 2 :

Get Details in Magento 1

In Magento 1 you can get the details simly as below-


Magento get current category Id

Syntax to get current Category Id :

Magento Load Category By Id


Now we will use the above category id to load category details and other information-

Load Category By Id :

Now you can get category details such as name, url etc.

Magento get category Name By Category Id

Syntax to get Category Name Id :

Magento get category Url By Category Id

Syntax to get Category Url :

Magento get category Description By Category Id

Syntax to get Category Description :

Magento get category Level By Category Id

Syntax to get Category Level :

Magento get category Image Url By Category Id

Syntax to get Category Image Url :

Magento get category Thumbnail Image Url By Category Id

Syntax to get Category Thumbnail Image Url :

Magento Load Category Products Collection

If you want to load products in individual category by id you can get all products as below .


Magento Load Category Products Collection By Category Id

Category Products Collection :

The above example will load all products of the category.

Note : In the above example we have selected all attributes
->addAttributeToSelect(‘*’);. We suggest not to select all attributes while getting the products collection, select the attributes which you need to display because it may slow down the system performance.

Advertisements