//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();
またはこの1つは、おそらくあなたが持っていた編集の問題であなたを助けます
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");
、カテゴリ名とIDの使用を取得するための)
これを行う方法に関する記事のns。 Google、StackOverflow、MagentoCommerceにはたくさんの例があります。ここからの1つです:http://stackoverflow.com/questions/5232879/how-to-get-sub-categories-of-a-specific-parent-category – seanbreeden
重複した質問 – ShaunOReilly
カテゴリを一緒にエコーします。私の質問は、2つのカテゴリ名の間にコンテンツを配置する必要があるため、製品ビューテンプレートを使って個別に、個別にエコーする方法です。 – James