0

When you select: Category>Display Settings>Display Mode>Static Block and Products the Static block that is selected gets displayed above the products by default. For some pages I want the static block to be diplayed below the products. I would like to be able to do this from the Custom Design Tab by adding a Custom Layout Update. Here is the code from my catalog.xml

<catalog_category_default translate="label">
    <label>Catalog Category (Non-Anchor)</label>
    <reference name="left">
        <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml">
            <action method="unsetChild"><child>category_filter</child></action>
            <block type="core/text_list" name="catalog.leftnav.state.renderers" as="state_renderers" />
        </block>
    </reference>
    <reference name="content">
        <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
            <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
                <action method="setDefaultDirection"><dir>desc</dir></action>
                <block type="core/text_list" name="product_list.name.after" as="name.after" />
                <block type="core/text_list" name="product_list.after" as="after" />
                <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                    <block type="page/html_pager" name="product_list_toolbar_pager"/>
                    <!-- The following code shows how to set your own pager increments -->
                    <!--
                        <action method="setDefaultListPerPage"><limit>4</limit></action>
                        <action method="setDefaultGridPerPage"><limit>9</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>2</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>4</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>6</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>8</limit></action>
                        <action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
                    -->
                </block>
                <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
                <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
                <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
                <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
                <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
                <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
            </block>
        </block>
    </reference>
    <reference name="main_top">
        <block type="core/template" name="filter.one" template="typostores/filter/filterone.phtml"
               before="-">
            <action method="insert"><child>catalog.leftnav</child></action>
        </block>
    </reference>
</catalog_category_default>

The line relating to the static block being displayed is:

<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">

And I need it displayed after the product list block.

I know how to edit the catalog.xml to display it like this on all pages but I only want it on a few hence why I would like to add a Custom Layout Update.

Please Help

2

You will need to edit catalog/category/view.phtml for this, not the layout file.

In view.phtml, you can see this:

<?php if($this->isContentMode()): ?>
    <?php echo $this->getCmsBlockHtml() ?>

<?php elseif($this->isMixedMode()): ?>
    <?php echo $this->getCmsBlockHtml() ?>
    <?php echo $this->getProductListHtml() ?>

<?php else: ?>
    <?php echo $this->getProductListHtml() ?>
<?php endif; ?>

You will want to add your condition for <?php echo $this->getCmsBlockHtml() ?> like this:

<?php $categories = array('1' => '1', '2' => '2', '4' => '4'); //your list of categories?>
<?php if(in_array(Mage::registry('current_category')->getId(), $categories)):?>
    <?php if($this->isContentMode()): ?>
        <?php echo $this->getCmsBlockHtml() ?>
    <?php elseif(!$this->isMixedMode()): ?>
        <?php echo $this->getProductListHtml() ?>
    <?php else: ?>
        <?php echo $this->getProductListHtml() ?>
        <?php echo $this->getCmsBlockHtml() ?>
    <?php endif; ?>

<?php else:?>
    <?php if($this->isContentMode()): ?>
        <?php echo $this->getCmsBlockHtml() ?>
    <?php elseif($this->isMixedMode()): ?>
        <?php echo $this->getCmsBlockHtml() ?>
        <?php echo $this->getProductListHtml() ?>
    <?php else: ?>
        <?php echo $this->getProductListHtml() ?>
    <?php endif; ?>

<?php endif; ?>

Note: if Mage::registry('current_category')->getId() doesn't gives you current category ID then you would want to use this $this->getLayout()->getBlock('category.products')->getCurrentCategory();. This should work.

  • Worked like a charm. Small syntax error after //your list of categories you need ?>. Could you explain something for me. I believe mixed mode is display Static Block and Products but if the category id is in the array it runs the else: option. Why is that?? – Pragman Feb 13 '17 at 1:42
  • If product id is in the array then it shouldn't run else. My guess is Mage::registry('current_category')->getId() is not returning value. – Adarsh Khatri Feb 13 '17 at 1:56
  • Sorry I should have been more specific it runs: <?php else: ?> <?php echo $this->getProductListHtml() ?> <?php echo $this->getCmsBlockHtml() ?> instead of the MixedMode() – Pragman Feb 13 '17 at 2:12
  • That means, in your category you haven chosen to have static block and catalog together. – Adarsh Khatri Feb 13 '17 at 2:14
  • But I have it set to static block and catalog thats what I can't figure out. But it is still renedering the Block after the Products which is what I want just don understand it??? – Pragman Feb 13 '17 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.