dongtao4787 2014-10-13 13:07
浏览 31
已采纳

Magento 1.9在页脚中显示最新的产品

EDIT: It turns out that the solution below was in fact the correct one. It turns out that my vagrant box didn't have php5-gd installed and so magento was failing to do image stuff, but PHP wasn't showing an error to say it wasn't installed. So make sure you install php5-gd :P

Good day!

I'm currently working on a Magento 1.9 based e-commerce website and I'm basically picking it up as I go along. I am currently taking a static design and turing it into a Magento theme.

I'm trying to show images (with links) to the 6 newest products in the store in the footer area of the store, but the tutorials and questions I have found haven't worked for me.

I have basically taken my footer from the static template and pasted it into my themes footer.phtml file. The design calls for the six images to be displayed like this in the html (if that makes sense?)

<div class="medium-6 large-3 columns newlyAdded">
    <div class="footerHat"></div>
    <h3> Newly Added</h3>
    <div class="row">
        <ul class="small-block-grid-3">
            <li><img src="./images/footer-image-1.jpg" alt="footer image"></li>
            <li><img src="./images/footer-image-2.jpg" alt="footer image"></li>
            <li><img src="./images/footer-image-3.jpg" alt="footer image"></li>
        </ul>
    </div>
    <p></p>
    <div class="row">
        <ul class="small-block-grid-3">
            <li><img src="./images/footer-image-4.jpg" alt="footer image"></li>
            <li><img src="./images/footer-image-5.jpg" alt="footer image"></li>
            <li><img src="./images/footer-image-6.jpg" alt="footer image"></li>
        </ul>
    </div>
</div>

My initial thought was to stick this into a static block and then loop over some stuff from a model in Magento, but I'm not sure if that is the best way.

Any help would be greatly appreciated, and of course I will provide as much information as I can :)

Thanks

EDIT: Extra Info

footer related stuff in the page.xml file:

<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
    <block type="page/html_wrapper" name="bottom.container" as="bottomContainer" translate="label">
        <label>Page Footer</label>
        <action method="setElementClass"><value>bottom-container</value></action>
    </block>
    <block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
    <block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>
</block>

<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
    <label>Page Bottom</label>
    <block type="page/html_cookieNotice" name="global_cookie_notice" as ="global_cookie_notice" template="page/html/cookienotice.phtml" before="-" />
</block>

<reference name="footer">
    <block type="catalog/product_new" name="home.catalog.product.new" alias="product_new" template="catalog/product/new.phtml">
        <action method="setProductsCount"><count>4</count></action>
    </block>
</reference>

footer.phtml file (default magento version)

<div class="footer-container">
    <div class="footer">
        <?php echo $this->getChildHtml() ?>
        <p class="bugs"><?php echo $this->__('Help Us to Keep Magento Healthy') ?> - <a href="http://www.magentocommerce.com/bug-tracking" onclick="this.target='_blank'"><strong><?php echo $this->__('Report All Bugs') ?></strong></a> <?php echo $this->__('(ver. %s)', Mage::getVersion()) ?></p>
        <address><?php echo $this->getCopyright() ?></address>
    </div>
</div>

the custom_page.xml:

<?xml version="1.0"?>
<layout>
    <custom_layout translate="label">
        <label>Custom layout</label>
        <reference name="root">
            <action method="setTemplate"><template>page/custom_layout.phtml</template></action>
            <action method="setIsHandle"><applied>1</applied></action>
        </reference>
    </custom_layout>
</layout>
  • 写回答

1条回答 默认 最新

  • douchuo9476 2014-10-13 13:37
    关注

    Magento already has this functionality you can use the following code to display the new products in footer/whichever location you want to display

    <reference name="footer">
    <block type="catalog/product_new" name="home.catalog.product.new" alias="product_new" template="catalog/product/new.phtml" after="cms_page">
    <action method="setProductsCount"><count>4</count></action>
    </block>
    </reference>
    

    NOTE That I'm considering you have followed Magento's way of theming and have "reference footer" if you want you can put the block code inside any reference call and may call it directly in your footer.phtml.

    If you want to style the layout create a copy of "app/design/frontend/base/default/template/catalog/product/new.phtml" in "app/design/frontend/{themepackage}/{themename}/template/catalog/product/new.phtml" and modify the layout.

    Feel free to comment if you have any doubts! Hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧