I am trying to get a static block to pull information. Using Magento 1.7 CE.
In the static box I am using the following code:
<div>{{block type="catalog/product_list" category_id="6" template="catalog/product/listmenu.phtml"}}</div>
I want this to display the product name, price, and image... What do I list in the listmenu.phtml so it pulls the correct information?
Given that the block type is "catalog/product_list", you can access the functionality of the block Mage_Catalog_Block_Product_List, i.e. a product collection loaded by the category id. So the approximate code outputting a list of products and their names, images, and prices would be:
<?php
$_productCollection=$this->getLoadedProductCollection();
foreach ($_productCollection as $_product): ?>
<div>
<h4><?php echo $this->stripTags($_product->getName());?></h4>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135);
?>" width="135" height="135" alt="<?php
echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
<?php endforeach; ?>
Related
I have use Fishpig extension in my website.
But i need to show Next and Previous link with it's appropriate featured image.
Can anyone please provide appropriate suggestion for this requirement.
Thanks,
The following code loads a post with the ID of 5 and if a featured image is set, it displays the image and a link to the post.
<?php $post = Mage::getModel('wordpress/post')->load(5) ?>
<?php if ($post->getId()): ?>
<?php if ($image = $post->getFeaturedImage()): ?>
<a href="<?php echo $post->getPermalink() ?>">
<img src="<?php echo $image->getAvailableImage() ?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/>
</a>
<?php endif; ?>
<?php endif; ?>
You can find more information on how to get different sized images from the featured image object at the URL below:
https://fishpig.co.uk/magento/wordpress-integration/post-images/
The following article explains how to get an image object from a post object.
https://fishpig.co.uk/magento/wordpress-integration/post-images/
Specifically:
<?php // $post is already defined ?>
<?php if ($featuredImage = $post->getFeaturedImage()): ?>
<a href="<?php echo $post->getPermalink() ?>">
<img src="<?php echo $featuredImage->getAvailableImage() ?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/>
</a>
<?php endif; ?>
I'm having a problem with the product page on a Magento site I'm working on.
I'm using the following code in a static block to display products in the header section:
{{block type="catalog/product_list" category_id="4" template="catalog/product/custom_list.phtml"}}
The thing is, the block is displaying fine on all pages except on the "product" page. Am I missing something here?
Hope you guys can help me.
custom_list.phtml:
<?php
$_productCollection = $this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="cat-product-list">
<ul class="products-grid">
<?php foreach ($_productCollection as $_product): ?>
<li class="item">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(90,60)->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(TRUE); ?>" width="90" height="60" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>
It turns out that the products won't show up on the product page unless the category (category_id="4") is the same as the category of the product you are viewing. Found that
in List.php.
if (Mage::registry('product')) {
$categories = Mage::registry('product')->getCategoryCollection()
->setPage(1, 1)
->load();
if ($categories->count()) {
$this->setCategoryId(current($categories->getIterator()));
}
}
I've added a local copy of the List.php file and modified it to my needs.
It is working fine now.
Looking at your code
{{block type="catalog/product_list" category_id="4" template="catalog/product/custom_list.phtml"}}
It appears you're using a non-stock template file to render the block. (catalog/product/custom_list.phtml). If I was debugging this problem myself I'd start by looking at the logic inside that template and figuring out why it wasn't displaying a collection on the product page.
I need to list thumbnail images that are only in stock but i cant find the way to insert the filter to say addAttributeToFilter('is_saleable', TRUE) to the next code.
The structure of product:
2 Options
Color and Size
All sku's are associated to the configurable product, and Gallery image have the Color Label that Match with the Color form Option.
When you open the Configurable product in product view page, this show a dropdown or checkbox form, that allow you to select the Color first then Show all Sizes in stock. But in the dropdown show only Colors that are in stock.
Example:
Red => S,M,L
Blue => L,XL
Yellow => S
Gray => Not in stock, not in the dropdown.
Is there any way to insert a filter to skip images colors that are not saleable or in stock?
<?php $_gallery = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
<?php $imgcount = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages()->count();?>
<?php if($imgcount >1): ?>
<div class="more-views">
<a href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo html_entity_decode($_helper->productAttribute($_product, $_product->getName(), 'name')); ?> <?php // echo $this->htmlEscape($_image->getLabel()) ?>">
<img style="padding-top:2px;" src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(33, 31); ?>" width="33" height="31" alt="<?php echo html_entity_decode($_helper->productAttribute($_product, $_product->getName(), 'name')); ?> <?php echo $this->htmlEscape($_image->getLabel()); ?>" title="<?php echo html_entity_decode($_helper->productAttribute($_product, $_product->getName(), 'name')); ?> <?php echo $this->htmlEscape($_image->getLabel()); ?>" />
</div>
<?php endif; ?>
I can see how media.phtml (with Cloud Zoom extension) is listing all the images on the product page by help of $this->getGalleryImages():
<?php foreach ($this->getGalleryImages() as $_image): ?>
<?php ... ?>
<?php endforeach; ?>
But when I use $this->getGalleryImages() in view.phtml which is the catalog product page template, it doesn't return or output anything. However, this would only print the first image on the product page:
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'image')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->setWatermarkImageOpacity(0)->resize(300, null);?>" alt="<?php echo $this->htmlEscape($this->getImageLabel());?>" title="<?php echo $this->htmlEscape($this->getImageLabel());?>" />
My question is how can I iterate through and display all the product images on the product page (view.phtml, not media.phtml)? Basically, I want them all on display on the page without thumbnailing or zooming or anything, just plain big images, one after another.
Thanks!
Here is the code for showing product image gallery..
Thanks,
Jeet
<?php $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
<?php if($_images){?>
<?php $i=0; foreach($_images as $_image){ $i++; ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(108,90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php $this->htmlEscape($_image->getLabel());?>" /><?php } ?>
<?php } ?>
I have a category called "Top Products". I wish to display this in a panel on my home page. What is the best way to do this in magento.
** edit **
Thanks sdek, i now have the following. In Home Page / Design.
<block type="catalog/product_list" category_id="13" template="catalog/product/featured.phtml"/>
And it is displaying products. However i have the following issues.
- it's not displaying products from category_id 13, It seems like this value is not being passed thru
- it's only display 2 products. I wish to display all.
featured.phtml
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<h2>Featured Products </h2>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="product-grid">
<?php endif ?>
<li class="<?php if(($i-1)%$_columnCount==0): ?> first<?php else: ?> last<?php endif; ?>">
<a class="product-image" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" >
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(85); ?>" class="product-img" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" style="padding-bottom:20px; margin-bottom:20px;" />
</a>
<p><strong><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></strong>
<?php echo $_product->getShortDescription(); ?></p>
<?php echo $this->getPriceHtml($_product, true) ?>
More details
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<?php endif; ?
I wouldn't even use a category but this extension instead:
Featured Products
The Featured Products extension mentioned by clockworkgeek is a good idea. But if you don't like that option the easiest thing to do is to add this in your home page cms
{{block type="catalog/product_list" category_id="YOUR_CAT_ID" template="catalog/product/YOUR_MODIFIED_COPY_OF_LIST.phtml"}}
And then make a copy of app/design/frontend///template/catalog/product/list.phtml (I refered to it above as YOUR_MODIFIED_COPY_OF_LIST.phtml) and remove the two lines that say
<?php echo $this->getToolbarHtml() ?>
and remove the entire if-block that outputs the "list mode"... basically the if statement
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
and you should only have the "grid mode" code in there.