Skip to main content
deleted 1 character in body
Source Link
Wajahat Bashir
  • 412
  • 1
  • 4
  • 24

I have use this code, products are coming but images are not showing. anyone can correct this code. thanks

  <?php
$totalPerPage =4;
$storeId = Mage::app()->getStore()->getId();
$_productCollection = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToSelect('*')
    ->setStoreId($storeId)
    ->addStoreFilter($storeId)
    ->addViewsCount()
    ->setPageSize($totalPerPage);
?>
<?php $_collectionSize = $_productCollection->count(); ?>

<?php if ($_collectionSize) { ?>
    <h2 class="subtitle">Most Viewed Products</h2>
    <ul class="products-grid">
        <?php
        foreach ($_productCollection as $_product):
        $image_url = $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,300);;;
        $alt = $this->htmlEscape($this->stripTags($this->getImageLabel($_product, 'small_image'), null, true));
        ?>
        <li class="item">
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                <img src="<?php echo $image_url; ?>" alt="<?php echo trim($alt)? $alt: $this->htmlEscape($this->stripTags($_product->getName())); ?>" />
            </a>
            <div class="product-info">
                <h2 class="product-name">
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                        <?php echo trim($alt)? $alt: $this->htmlEscape($this->stripTags($_product->getName())); ?>
                    </a>
                </h2>
            </div>
        </li>
        <?php endforeach; ?>
    </ul>
<?php } ?>

I have use this code, products are coming but images are not showing. anyone can correct this code. thanks

  <?php
$totalPerPage =4;
$storeId = Mage::app()->getStore()->getId();
$_productCollection = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToSelect('*')
    ->setStoreId($storeId)
    ->addStoreFilter($storeId)
    ->addViewsCount()
    ->setPageSize($totalPerPage);
?>
<?php $_collectionSize = $_productCollection->count(); ?>

<?php if ($_collectionSize) { ?>
    <h2 class="subtitle">Most Viewed Products</h2>
    <ul class="products-grid">
        <?php
        foreach ($_productCollection as $_product):
        $image_url = $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,300);;
        $alt = $this->htmlEscape($this->stripTags($this->getImageLabel($_product, 'small_image'), null, true));
        ?>
        <li class="item">
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                <img src="<?php echo $image_url; ?>" alt="<?php echo trim($alt)? $alt: $this->htmlEscape($this->stripTags($_product->getName())); ?>" />
            </a>
            <div class="product-info">
                <h2 class="product-name">
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                        <?php echo trim($alt)? $alt: $this->htmlEscape($this->stripTags($_product->getName())); ?>
                    </a>
                </h2>
            </div>
        </li>
        <?php endforeach; ?>
    </ul>
<?php } ?>

I have use this code, products are coming but images are not showing. anyone can correct this code. thanks

  <?php
$totalPerPage =4;
$storeId = Mage::app()->getStore()->getId();
$_productCollection = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToSelect('*')
    ->setStoreId($storeId)
    ->addStoreFilter($storeId)
    ->addViewsCount()
    ->setPageSize($totalPerPage);
?>
<?php $_collectionSize = $_productCollection->count(); ?>

<?php if ($_collectionSize) { ?>
    <h2 class="subtitle">Most Viewed Products</h2>
    <ul class="products-grid">
        <?php
        foreach ($_productCollection as $_product):
        $image_url = $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,300);
        $alt = $this->htmlEscape($this->stripTags($this->getImageLabel($_product, 'small_image'), null, true));
        ?>
        <li class="item">
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                <img src="<?php echo $image_url; ?>" alt="<?php echo trim($alt)? $alt: $this->htmlEscape($this->stripTags($_product->getName())); ?>" />
            </a>
            <div class="product-info">
                <h2 class="product-name">
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                        <?php echo trim($alt)? $alt: $this->htmlEscape($this->stripTags($_product->getName())); ?>
                    </a>
                </h2>
            </div>
        </li>
        <?php endforeach; ?>
    </ul>
<?php } ?>
Source Link
Wajahat Bashir
  • 412
  • 1
  • 4
  • 24

How to Display the Most viewed Products with images in Magento 1.9.2?

I have use this code, products are coming but images are not showing. anyone can correct this code. thanks

  <?php
$totalPerPage =4;
$storeId = Mage::app()->getStore()->getId();
$_productCollection = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToSelect('*')
    ->setStoreId($storeId)
    ->addStoreFilter($storeId)
    ->addViewsCount()
    ->setPageSize($totalPerPage);
?>
<?php $_collectionSize = $_productCollection->count(); ?>

<?php if ($_collectionSize) { ?>
    <h2 class="subtitle">Most Viewed Products</h2>
    <ul class="products-grid">
        <?php
        foreach ($_productCollection as $_product):
        $image_url = $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,300);;
        $alt = $this->htmlEscape($this->stripTags($this->getImageLabel($_product, 'small_image'), null, true));
        ?>
        <li class="item">
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                <img src="<?php echo $image_url; ?>" alt="<?php echo trim($alt)? $alt: $this->htmlEscape($this->stripTags($_product->getName())); ?>" />
            </a>
            <div class="product-info">
                <h2 class="product-name">
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                        <?php echo trim($alt)? $alt: $this->htmlEscape($this->stripTags($_product->getName())); ?>
                    </a>
                </h2>
            </div>
        </li>
        <?php endforeach; ?>
    </ul>
<?php } ?>