0

我目前处于紧要关头,需要对我网站上的一些现有代码进行调整。有一个 PHP SQL 查询需要修改以从特定类别中提取产品。然后将该列表输入 HTML 产品轮播。无论如何,目前它正在拉入所有带有图像的产品。

<?php
 $query = mysql_query("SELECT * FROM `catalog_product_flat_1` WHERE `small_image` != 'no_selection'");
 //$query = mysql_query("SELECT * FROM `catalog_product_flat_1` WHERE `category_ID` = 16");
 while($fins = mysql_fetch_array($query)) {
                ?>

注释的代码行是我试图做的,但没有运气。我在这里在黑暗中拍摄。从任何标准来看,我都不是 Magento 或 PHP 专家。仅供参考,前端显示我想要的类别的类别 ID 为 16。按名称提取它会很好,但为了简单/速度起见,我可以使用 ID。

感谢您的任何帮助。

(更新 8-27)整个 HTML 代码块:

<div class="whiteGradientLarge span-10">
    <div class="content">
        <h2>Latest Products</h2>
        <div class="span-10">
            <a href="#" class="prev left"><img src="assets/arrowPrev.png" /></a>
            <ul class="productSlider push-1">

                <?php
                //$query = mysql_query("SELECT * FROM `catalog_product_flat_1` WHERE `small_image` != 'no_selection'");
                //while($products = mysql_fetch_array($query)) {
                $category = new Mage_Catalog_Model_Category();
                $category->load('16'); //your category id here, 16 $catid
                $prodCollection = $category->getProductCollection();
                foreach ($prodCollection as $product) {
                //get all the product information here... //}
                    ?>
                    <li class="roundabout-moveable-item">
                    <h3><a href="http://www.mywebsite.com/store/products/<?php echo $product['url_path']; ?>"><?php echo $product['name']; ?></a></h3> 
                    <img src="https://www.mywebsite.com/store/media/catalog/product<?php echo $product['small_image']; ?>" />
                    <span class="productTitle span-3"><?php  ?></span>
                    </li>
                <?php 
                } ?>
            </ul>
            <a href="#" class="next right"><img src="assets/arrowNext.png" /></a>
        </div>
    </div>

</div>
4

1 回答 1

1
$category = new Mage_Catalog_Model_Category();
$category->load($catid); //your category id here, 16
$prodCollection = $category->getProductCollection();
foreach ($prodCollection as $product) {
    //get all the product information here...

    ?>
    <li class="roundabout-moveable-item">
         <h3><a href="http://www.mywebsite.com/store/products/<?php echo $product->getUrlPath(); ?>"><?php echo $product->getName(); ?></a></h3> 
         <img src="https://www.mywebsite.com/store/media/catalog/product<?php echo $product->getSmallImage(); ?>" />
         <span class="productTitle span-3"><?php  ?></span>
    </li>
 <?php 
}
于 2012-08-23T15:11:39.047 回答