[英]How to get all categories and subcategories name in Virtuemart
我創建了一個HTML模塊並加載了viemart的類別布局,但我需要顯示所有類別和子類別的列表,這樣當用戶將來添加新類別時,它會自動更新。 無需每次都進行硬編碼。 請提供有關此主題的幫助。 您可以通過在PHP中使用while循環來加載這些類別名稱。 請快速回復。
嘗試這個,
如果您正在使用模塊,則在模塊文件( mod_yourmodule.php
)中添加以下代碼。
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
$categoryModel = VmModel::getModel('Category');
$cats = $categoryModel->getCategoryTree();//Params $parentId=0, $level = 0, $onlyPublished = true,$keyword = ''
echo "<pre/>";
print_r($cats);
希望能有所幫助
由於VirtueMart在前端不提供此層次結構,因此您必須構建自己的方法。 盡管在后端,您可以使用@Jobin的答案。 我已經為前端實現並測試了它,它很容易工作。 在這里檢查答案
https://webkul.com/blog/get-parent-child-categories-hierarchical-tree-joomla-virtuemart/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.