我设法使用div的图像使Owl Carousel在我的Magento主页上正常工作。

我的目标是使它与产品混为一谈,但我一直在努力。

我想显示特定类别的产品,并使用Owl Carousel将其显示在主页上,但是我通常使用带有以下代码的cms块将产品调用到主页上:

{{block type="catalog/product_list" category_id="112" column_count="4" template="catalog/product/list.phtml"}}


这种讨厌的做法不起作用-产品显示出来,但是由于模板的原因,它们具有自己的布局。

有没有人对我可以使用php或cms块阻止从类别中调用产品的任何想法,因此它可以与owl carousel一起使用。

提前致谢。

最佳答案

首先,假设您不打算将大量产品加载到Owl Carousel中,并且创建一个类别只是为了存储要放在滑块中的产品,就可以了。

<div class="owl-carousel">

<?php

   $categoryId = 15; // this is the category holding your products
   $products = Mage::getSingleton('catalog/category')->load($categoryId) // load the category
               ->getProductCollection() // and the products
               ->addAttributeToSelect('image'); // tell Magento which attributes to get

   foreach ($products as $product) { // iterate through the entire collection
        echo '<div class="item"><img src='.$product->getImageUrl().'></div>'; // print the image url inside of the required Owl markup
   }

?>

</div>


上面的内容也应该适当地组织起来,将要调用的变量出现在块的顶部,而foreach仅出现在块的Owl部分。

foreach应该放在Owl Carousel标记内,因为除了Magento属性外,我们还在打印Owl标记。

关于php - Owl Carousel -Magento产品,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32748397/

10-11 22:28
查看更多