简体   繁体   English

如何在 Magento 2 中检索父类别 URL?

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

I have coded a widget for Magento 2.3 that lists subcategories based on a parent category ID entered into the Magento admin panel.我为 Magento 2.3 编写了一个小部件,它根据输入到 Magento 管理面板的父类别 ID 列出子类别。 If there are more than 10 subcategories listed, it displays a "View All" link so the visitor can view all additional subcategories.如果列出的子类别超过 10 个,则会显示“查看全部”链接,以便访问者可以查看所有其他子类别。

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>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM