PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 23, 2022

[FIXED] How to retrieve parent category URL in Magento 2?

 August 23, 2022     html, magento, magento2, php     No comments   

Issue

I have coded a widget for Magento 2.3 that lists subcategories based on a parent category ID entered into the Magento admin panel. If there are more than 10 subcategories listed, it displays a "View All" link so the visitor can view all additional subcategories.

The link is conditional, where if there is no subcategory, it should display the "View All" link and link to the parent category that is being pulled from the admin panel. However, I cannot find the correct parameters for the parent category. This is my code minus the correct parameters:

<a href="<?php if (!empty($subcat)) {echo $subcat->getParentCategory()->getUrl();} else {echo MISSING_PARENT_CAT_URL_PARAMETER;} ?>">View All Categories...</a>


Solution

<?php if ($i >= '$numberofcats') { ?>
<a href="<?php {echo $subcat->getParentCategory()->getUrl();}?>">View All</a>
<?php } else { echo '';} ?>


Answered By - Petey88
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing