show category name in product detail pageHow to display category name in product page?Magento2 : Show category name on product detail pageMagento 2 - Show subcategories (and products) on category pageBannerslider not compatible with Magento 2.1?Uncaught TypeError: Argument 1 passed to […] must be an instance ofShow Upsell Product in product detail pageMagento replace home by categoryMagento 2.2 - Breadcrumbs issueMagento 2.2.3 Order variables in success pageMagento 2, category disappeared on “Catalog > Category” tree, does show everywhere else

Source of the Wildfire?

Do not cross the line!

Motorola 6845 and bitwise graphics

Do Grothendieck universes matter for an algebraic geometer?

How to not get blinded by an attack at dawn

Did galley captains put corks in the mouths of slave rowers to keep them quiet?

Fixed width with p doesn't work

Developers demotivated due to working on same project for more than 2 years

Why weren't the bells paid heed to in S8E5?

Was the dragon prowess intentionally downplayed in S08E04?

Is there any good reason to write "it is easy to see"?

How to describe a building set which is like LEGO without using the "LEGO" word?

"Every hiker climbed a hill", is there one or multiple hills?

Why doesn't Iron Man's action affect this person in Endgame?

Will a coyote attack my dog on a leash while I'm on a hiking trail?

Filter a data-frame and add a new column according to the given condition

Why do the lights go out when someone enters the dining room on this ship?

Can my Serbian girlfriend apply for a UK Standard Visitor visa and stay for the whole 6 months?

Substring join or additional table, which is faster?

Uh oh, the propeller fell off

How to redirect stdout to a file, and stdout+stderr to another one?

complicated arrows in flowcharts

How do I adjust encounters to challenge my lycanthrope players without negating their cool new abilities?

Why are solar panels kept tilted?



show category name in product detail page


How to display category name in product page?Magento2 : Show category name on product detail pageMagento 2 - Show subcategories (and products) on category pageBannerslider not compatible with Magento 2.1?Uncaught TypeError: Argument 1 passed to […] must be an instance ofShow Upsell Product in product detail pageMagento replace home by categoryMagento 2.2 - Breadcrumbs issueMagento 2.2.3 Order variables in success pageMagento 2, category disappeared on “Catalog > Category” tree, does show everywhere else






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am trying to get the name of a category in the addtocart.phtml. I know products could be assigned to more then one category so I am fine with having a loop if need be. Anyway here is my code which i thought would display the name of the category that the product is in/being viewed in.
does anyone know how I should alter this?



 $objectManager = MagentoFrameworkAppObjectManager::getInstance();
$category = $objectManager->get('MagentoFrameworkRegistry')->registry('current_category');//get current category
$category_name = $category->getName();









share|improve this question






















  • Please check magento.stackexchange.com/questions/202423/…

    – BartZalas
    May 9 at 21:27











  • using product id get all category name which assign this product ??

    – Rk Rathod
    May 10 at 5:32











  • Possible duplicate of How to display category name in product page?

    – Rakesh Donga
    May 10 at 5:42

















1















I am trying to get the name of a category in the addtocart.phtml. I know products could be assigned to more then one category so I am fine with having a loop if need be. Anyway here is my code which i thought would display the name of the category that the product is in/being viewed in.
does anyone know how I should alter this?



 $objectManager = MagentoFrameworkAppObjectManager::getInstance();
$category = $objectManager->get('MagentoFrameworkRegistry')->registry('current_category');//get current category
$category_name = $category->getName();









share|improve this question






















  • Please check magento.stackexchange.com/questions/202423/…

    – BartZalas
    May 9 at 21:27











  • using product id get all category name which assign this product ??

    – Rk Rathod
    May 10 at 5:32











  • Possible duplicate of How to display category name in product page?

    – Rakesh Donga
    May 10 at 5:42













1












1








1








I am trying to get the name of a category in the addtocart.phtml. I know products could be assigned to more then one category so I am fine with having a loop if need be. Anyway here is my code which i thought would display the name of the category that the product is in/being viewed in.
does anyone know how I should alter this?



 $objectManager = MagentoFrameworkAppObjectManager::getInstance();
$category = $objectManager->get('MagentoFrameworkRegistry')->registry('current_category');//get current category
$category_name = $category->getName();









share|improve this question














I am trying to get the name of a category in the addtocart.phtml. I know products could be assigned to more then one category so I am fine with having a loop if need be. Anyway here is my code which i thought would display the name of the category that the product is in/being viewed in.
does anyone know how I should alter this?



 $objectManager = MagentoFrameworkAppObjectManager::getInstance();
$category = $objectManager->get('MagentoFrameworkRegistry')->registry('current_category');//get current category
$category_name = $category->getName();






magento2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 9 at 18:11









JayreisJayreis

322933




322933












  • Please check magento.stackexchange.com/questions/202423/…

    – BartZalas
    May 9 at 21:27











  • using product id get all category name which assign this product ??

    – Rk Rathod
    May 10 at 5:32











  • Possible duplicate of How to display category name in product page?

    – Rakesh Donga
    May 10 at 5:42

















  • Please check magento.stackexchange.com/questions/202423/…

    – BartZalas
    May 9 at 21:27











  • using product id get all category name which assign this product ??

    – Rk Rathod
    May 10 at 5:32











  • Possible duplicate of How to display category name in product page?

    – Rakesh Donga
    May 10 at 5:42
















Please check magento.stackexchange.com/questions/202423/…

– BartZalas
May 9 at 21:27





Please check magento.stackexchange.com/questions/202423/…

– BartZalas
May 9 at 21:27













using product id get all category name which assign this product ??

– Rk Rathod
May 10 at 5:32





using product id get all category name which assign this product ??

– Rk Rathod
May 10 at 5:32













Possible duplicate of How to display category name in product page?

– Rakesh Donga
May 10 at 5:42





Possible duplicate of How to display category name in product page?

– Rakesh Donga
May 10 at 5:42










2 Answers
2






active

oldest

votes


















0














<?php 
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManager->get('MagentoFrameworkRegistry')->registry('current_product'); /* You will get current product from here */
$categories = $product->getCategoryIds(); /* You will get array of categories id */
foreach($categories as $category)
$catData = $objectManager->create('MagentoCatalogModelCategory')->load($category);
echo $catData->getName();


?>





share|improve this answer






























    0














    Using Product Id Get All Category Name Which Assign This Product



     $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $productFactory = $objectManager->get('MagentoCatalogModelProductFactory')->create()->load($product_id);
    $categoryIds = $productFactory->getCategoryIds();
    foreach($categoryIds as $category)

    $id = $category->getId();
    $categoryFactory = $objectManager->get('MagentoCatalogModelCategoryFactory')->create()->load($id);
    $categoryName = $categoryFactory->getName();






    share|improve this answer























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "479"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f274057%2fshow-category-name-in-product-detail-page%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      <?php 
      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $product = $objectManager->get('MagentoFrameworkRegistry')->registry('current_product'); /* You will get current product from here */
      $categories = $product->getCategoryIds(); /* You will get array of categories id */
      foreach($categories as $category)
      $catData = $objectManager->create('MagentoCatalogModelCategory')->load($category);
      echo $catData->getName();


      ?>





      share|improve this answer



























        0














        <?php 
        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
        $product = $objectManager->get('MagentoFrameworkRegistry')->registry('current_product'); /* You will get current product from here */
        $categories = $product->getCategoryIds(); /* You will get array of categories id */
        foreach($categories as $category)
        $catData = $objectManager->create('MagentoCatalogModelCategory')->load($category);
        echo $catData->getName();


        ?>





        share|improve this answer

























          0












          0








          0







          <?php 
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $product = $objectManager->get('MagentoFrameworkRegistry')->registry('current_product'); /* You will get current product from here */
          $categories = $product->getCategoryIds(); /* You will get array of categories id */
          foreach($categories as $category)
          $catData = $objectManager->create('MagentoCatalogModelCategory')->load($category);
          echo $catData->getName();


          ?>





          share|improve this answer













          <?php 
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $product = $objectManager->get('MagentoFrameworkRegistry')->registry('current_product'); /* You will get current product from here */
          $categories = $product->getCategoryIds(); /* You will get array of categories id */
          foreach($categories as $category)
          $catData = $objectManager->create('MagentoCatalogModelCategory')->load($category);
          echo $catData->getName();


          ?>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 9 at 18:44









          Saphal JhaSaphal Jha

          907616




          907616























              0














              Using Product Id Get All Category Name Which Assign This Product



               $objectManager = MagentoFrameworkAppObjectManager::getInstance();
              $productFactory = $objectManager->get('MagentoCatalogModelProductFactory')->create()->load($product_id);
              $categoryIds = $productFactory->getCategoryIds();
              foreach($categoryIds as $category)

              $id = $category->getId();
              $categoryFactory = $objectManager->get('MagentoCatalogModelCategoryFactory')->create()->load($id);
              $categoryName = $categoryFactory->getName();






              share|improve this answer



























                0














                Using Product Id Get All Category Name Which Assign This Product



                 $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                $productFactory = $objectManager->get('MagentoCatalogModelProductFactory')->create()->load($product_id);
                $categoryIds = $productFactory->getCategoryIds();
                foreach($categoryIds as $category)

                $id = $category->getId();
                $categoryFactory = $objectManager->get('MagentoCatalogModelCategoryFactory')->create()->load($id);
                $categoryName = $categoryFactory->getName();






                share|improve this answer

























                  0












                  0








                  0







                  Using Product Id Get All Category Name Which Assign This Product



                   $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                  $productFactory = $objectManager->get('MagentoCatalogModelProductFactory')->create()->load($product_id);
                  $categoryIds = $productFactory->getCategoryIds();
                  foreach($categoryIds as $category)

                  $id = $category->getId();
                  $categoryFactory = $objectManager->get('MagentoCatalogModelCategoryFactory')->create()->load($id);
                  $categoryName = $categoryFactory->getName();






                  share|improve this answer













                  Using Product Id Get All Category Name Which Assign This Product



                   $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                  $productFactory = $objectManager->get('MagentoCatalogModelProductFactory')->create()->load($product_id);
                  $categoryIds = $productFactory->getCategoryIds();
                  foreach($categoryIds as $category)

                  $id = $category->getId();
                  $categoryFactory = $objectManager->get('MagentoCatalogModelCategoryFactory')->create()->load($id);
                  $categoryName = $categoryFactory->getName();







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 10 at 5:41









                  Rk RathodRk Rathod

                  1,790214




                  1,790214



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Magento Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f274057%2fshow-category-name-in-product-detail-page%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

                      Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

                      Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림