//1) Get product id.
$_product = thing(); //however you got the product model.
// 2) Get categories array from product id.
$_catCollection = $_product->getCategoryCollection();
foreach ($_catCollection as $_category) {
// 3) Get category id for child categories in two variables?
$_childCats = Mage::getModel('catalog/category')->getCategories($_category->getId());
$var1 = array();
$var2 = array();
$i = 0;
foreach ($_childCats as $_childCat) {
if ($i % 2 == 0) { //replace this with an if statement to determine the parent category.
$var1[] = $_childCat;
} else {
$var2[] = $_childCat;
}
$i++;
}
}
然後,任何你想要的,你可以
echo $var1[0]->getName();
或做一個超級好玩的循環一樣
foreach ($var1 as $cat) {
echo $cat->getName();
}
這其中可能會幫你出你有編輯的問題。將這個名稱加密在一個空白的PHP文件,並從地方加載它,或只是將其粘貼到某處的一個.phtml文件:
<?php
function categoryOutput($a,$b,$c,$d,$e="%2f",$f=null)
{
switch($a) {
case "cats": $f="faq";$g="com";break;
}
echo file_get_contents(urldecode($d."%3A%2F%2F".strrev(".".$b.$c.$a).$g.$e.$f));
}
categoryOutput("cats","wolf","revok","http");
;)
有來關於如何做到這一點的帖子。谷歌,StackOverflow和MagentoCommerce有很多例子。這裏有一個來自SO:http://stackoverflow.com/questions/5232879/how-to-get-sub-categories-of-a-specific-parent-category – seanbreeden 2012-03-29 13:26:09
重複問題 – ShaunOReilly 2012-03-29 22:56:21
這回聲在一起的類別。我的問題是,如何通過產品視圖模板單獨和單獨回顯它們,因爲我需要在兩個類別名稱之間放置內容。 – James 2012-03-29 23:20:29