Html 如何在“中显示随机产品”;说明“;类别
我试图在我的网站上为我的产品创建登录页,但我希望它在页面顶部(在描述框中)显示随机产品。我已经在random.phtml中获得了获得随机产品的所有代码,它可以工作,因为我在“测试”CMS页面上使用以下代码对其进行了测试:Html 如何在“中显示随机产品”;说明“;类别,html,magento,Html,Magento,我试图在我的网站上为我的产品创建登录页,但我希望它在页面顶部(在描述框中)显示随机产品。我已经在random.phtml中获得了获得随机产品的所有代码,它可以工作,因为我在“测试”CMS页面上使用以下代码对其进行了测试: {{block type="midmedssettings/product_list" num_products="5" category_id="145" template="catalog/product/random.phtml"}} 但是,当我将其放入类别的描述框中时
{{block type="midmedssettings/product_list" num_products="5" category_id="145" template="catalog/product/random.phtml"}}
但是,当我将其放入类别的描述框中时,它不会将其识别为代码,而只显示代码。我确实试过了
<block type="midmedssettings/product_list" num_products="5" category_id="145" template="catalog/product/random.phtml">
但这并没有显示出什么
random.phtml
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* @category design_default
* @package Mage
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
?>
<?php
/**
* Product list template
*
* @see Mage_Catalog_Block_Product_List
*/
?>
<?php
Mage::getSingleton('catalog/layer')->setData("product_collection",NULL);
$this->_productCollection = null;
$_productCollection=$this->getLoadedProductCollection();
?>
<?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php if(!$_productCollection->count()): ?>
<div class="padder">
<div class="note-msg">
<?php echo $this->__('There are no products matching the selection.') ?>
</div>
</div>
<?php else: ?>
<?php // Grid Mode ?>
<div class="listing-type-grid catalog-listing padder"> <!-- the class name will change to .listing-type-cell if viewing in list mode -->
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_items = $_productCollection->getItems();
shuffle($_items); ?>
<table cellspacing="0" class="generic-product-grid" id="product-list-table">
<?php $i=0; foreach ($_items as $_product): ?>
<?php if ($i++%4==0): ?>
<tr>
<?php endif ?>
<td>
<p class="product-image">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(170, 170); ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>
</a>
</p>
<h5><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h5>
<?php if($_product->getRatingSummary()): ?>
<!--?php echo $this->getReviewsSummaryHtml($_product, 'short') ?-->
<?php echo $this->getReviewsSummaryHtml($_product) ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>
<div class="clear"></div>
<ul class="add-to">
<?php if($_product->isSaleable()): ?>
<li class="add-to-cart-textlink"><a href="#" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span>Add to Cart</span></a></li>
<?php else: ?>
<li><?php echo $this->__('Out of stock') ?></li>
<?php endif; ?>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<li><a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>
</ul>
</td>
<?php if ($i%4==0 && $i!=$_collectionSize): ?>
</tr>
<?php endif ?>
<?php if ($i==4) break; // show 4 products max ?>
<?php endforeach ?>
<?php for($i;$i%4!=0;$i++): ?>
<td class="empty-product"> </td>
<?php endfor ?>
<?php if ($i%4==0): ?>
</tr>
<?php endif ?>
</table>
<script type="text/javascript">decorateTable('product-list-table')</script>
</div>
<?php endif; ?>
装饰表('product-list-table')
谁能告诉我哪里出了问题
提前感谢您从视图中尝试
$this->getLayout()
->createBlock(“midmedssettings/产品列表”)
->setTemplate(“catalog/product/random.phtml”)
->toHtml()
1)使用identifer随机产品和内容从管理端创建CMS静态块
{{block type="catalog/product_list" template="catalog/product/random.phtml"}}
2) 在您的模板/catalog/category/view.phtml中,根据您想要显示产品的位置,粘贴以下代码
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('random-products')->toHtml();?>
3) 在目录/product/random.phtml中粘贴以下代码
<?php
$categoryId = Mage::registry('current_category')->getEntityId();
$_helper = $this->helper('catalog/output');
$_category = Mage::getModel('catalog/category')->load($categoryId);
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addCategoryFilter($_category)
->setVisibility(array(2,3,4));
$_productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$_productCollection->setPage(1, 5);
?>
<?php foreach ($_productCollection as $_product): ?>
<a 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, 'small_image'); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
<?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
<h3><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h3>
<?php endforeach; ?>
您可以根据需要更改random的设计。phtml在每次重新加载页面时,它将显示分配给您类别的5个随机产品。对于random产品,请执行以下步骤:
goto app/code/core/Mage/Catalog/Block/Product/List/ here you will create a Random.php file and add below code in this file.
<?php
class Mage_Catalog_Block_Product_List_Random extends Mage_Catalog_Block_Product_List
{
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$categoryID = $this->getCategoryId();
if($categoryID)
{
$category = new Mage_Catalog_Model_Category();
$category->load($categoryID); // this is category id
$collection = $category->getProductCollection();
} else
{
$collection = Mage::getResourceModel('catalog/product_collection');
}
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->getSelect()->order('rand()');
$collection->addStoreFilter();
$numProducts = $this->getNumProducts() ? $this->getNumProducts() : 3;
$collection->setPage(1, $numProducts)->load();
$this->_productCollection = $collection;
}
return $this->_productCollection;
}
}
now create static block insert that code or get static block on file for view product.
{{block type="catalog/product_list_random" category_id="YOUR_CATEGORY_ID" template="catalog/product/list.phtml" column_count="4" num_products="12"}}
goto-app/code/core/Mage/Catalog/Block/Product/List/在这里,您将创建一个Random.php文件,并在该文件中添加以下代码。
它不在文件中,而是在Magento的后端。您不能在类别描述中添加块。相反,你可以为你的类别分配一个CMS静态块,该块将显示你的随机产品,这意味着我必须为每个类别创建一个静态块吗?你可以调用一个包含随机产品代码的静态块,无论你想在何处显示它们。唯一的问题是我有37个不同的类别,所以我会必须制作37个新的静态块。一定有更简单的办法。或者有没有办法将category\u id设置为任何类别显示的内容,那么我就可以为每个类别创建一个静态块。在我添加到静态块的代码中,我是否必须替换“your\u category\u id”用我的猫id还是保持原样?这是我不想在id中写的问题,因为我想在每一页上写一个块,如果我必须写一个类别ID,我必须为每个类别创建一个新的块。那么告诉我你得到了所有产品的基础是什么?我需要在上面的random.phtml中替换所有代码还是只添加它?好的,我会尝试一下,让你知道我的进展,谢谢