Tuesday, April 24, 2012

Magento add category with images on homepage



if you would like to add category titles with images on the front page, just follow the steps:

place this snippet on your homepage cms page:

{{block type="core/template" name="homepage" template="catalog/category/homepagecategory.phtml"}}

then place this code in app/code/design/frontend/YOUR_PACKAGE/YOUR_TEMPLATE/catalog/category/homepagecategory.phtml

<?php
 $currcatId = 3;
 if($currcatId != NULL)
    {
  $collection = Mage::getModel('catalog/category')->getCategories($currcatId);
  $ctr = 0;
  foreach($collection as $subcat)
  {
      //limits the categories to be shown on home page to 6 categories
      if ($ctr < 6)
   if($subcat->getIsActive())
   {
       $category = Mage::getModel('catalog/category')->load($subcat->getEntityId());
       $ctr++;
       if (strtolower($category->getName()) == "overige lampen") 
       {
       }
    else
   {
?>

<div class="sub-category-container" style="margin-right:<?php if(($ctr % 2) == 0) {echo "0";} else {echo "8px";} ?>; margin-bottom:10px;" >
 <a href="<?php echo $this->getBaseUrl() . $category->getUrlKey() ?>" style="background:none; border:none;">
  <div>
     <?php if($_imgUrl = $category->getImageUrl()): ?>
   <img src="<?php echo $_imgUrl; ?>" border="0" />
     <?php else:?>
   <img src="<?php echo $this->getSkinUrl('images/lampen/placeholder.jpg') ?>" border="0" width="185px" height="185px" />
     <?php endif; ?>
  </div>
  <div>
   <a href="<?php echo $this->getBaseUrl() . $category->getUrlKey() ?>"><?php echo $category->getName(); ?></a>
  </div>
 </a>
</div>

<?php
     }
   }
  }
 }
?>

Magento 1.6 cannot login on admin

I have a sample Magento 1.6.2 installation wherein I test sample codes, install/test extension and also it acts as a quick reference whenever I'm not sure of anything on the admin area.
As you have guessed I tried loggin in one fine day and pooof! I can't login.. Tried almost anything (eg. clearing cache, session, locks ... using other web browser) but it still wont log me in..

Tried searching for a solution and thank God I found one on phpgenious..
It says that this is a cookie problem because Magento cannot create a cookie on your site, so here's the solution. (this solution worked for me..)

COPY app/code/core/Mage/Core/Model/Session/Abstract/Varien.php on app/code/local/Mage/Core/Model/Session/Abstract/Varien.php (so that it will not be overwritten when you upgrade)


        // session cookie params
        $cookieParams = array(
            'lifetime' => $cookie->getLifetime(),
            'path'     => $cookie->getPath()
            'domain'   => $cookie->getConfigDomain(),
            'secure'   => $cookie->isSecure(),
            'httponly' => $cookie->getHttponly()
        ); 

and replace it with:


        // session cookie params
        $cookieParams = array(
            'lifetime' => $cookie->getLifetime(),
            'path'     => $cookie->getPath()
           // 'domain'   => $cookie->getConfigDomain(),
           // 'secure'   => $cookie->isSecure(),
           // 'httponly' => $cookie->getHttponly()
        ); 

What we did here is we disabled the cookies check that Magento do when we try to login.. This should not be used on live site because cookies will work if you have a true domain.

Tuesday, April 12, 2011

Magento - How to make a quantity increment in product view?



Files needed, Files to be edited:
  • JQuery (probably the latest version, better if minified)
  • jincrement.js (this is our own js.. you can change its name as you like)
  • jQuery.noConflict()
  • styles.css (styling for the increment buttons)
  • layout/catalog.xml (this is where we'll reference our js, just being clean)
  • template/catalog/product/view/addtocart.phtml (we'll put a div here)
  1. create a file with the name jincrement.js and put this code on it..
  2. jQuery(document).ready(function(){
        var $j = jQuery.noConflict();
        $j("div.quantity").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');
        $j(".plus").click(function(){
            var currentVal = parseInt($j(this).prev(".qty").val());
            if (!currentVal || currentVal=="" || currentVal == "NaN") 
               currentVal = 0;
               $j(this).prev(".qty").val(currentVal + 1);
        });
        $j(".minus").click(function(){
            var currentVal = parseInt($j(this).next(".qty").val());
            if (currentVal == "NaN") 
                currentVal = 0;
                if (currentVal > 0){
                    $j(this).next(".qty").val(currentVal - 1);
                }
        });
    });
  3. Place the JQuery and jincrement.js on js/
  4. in catalog.xml
  5. <!--
    Product view
    -->
    <reference name="head">
                <action method="addJs"><script>jquery.min.js</script></action>
                <action method="addJs"><script>jquery.noconflict.js</script></action>
                <action method="addJs"><script>jquery.jincrement.js</script></action>
               ... OTHER CODES HERE ...
    </reference>
  6. in addtocart.phtml
    in line 34, enclose in <div class="quantity"></div> the input tag...

  7. style using styles.css.. this is my code for styling..
  8. div.add-to-cart div.quantity input#minus1{
        background-color: #A1A1A1;
        border: 1px solid #BBB;
        border-radius: 3px 0 0 3px;
        -moz-border-radius: 3px 0 0 3px;
        float: left;
        height: 20px;
        margin-right: 1px;
        padding-left: 2px;
        cursor: pointer;
    }
    div.add-to-cart div.quantity input#minus1:hover{
        background-color: #CCC;
        border: 1px solid #DDD;
    }
    div.add-to-cart div.quantity input#add1{
        background-color: #A1A1A1;
        border: 1px solid #BBB;
        border-radius: 0 3px 3px 0;
        -moz-border-radius: 0 3px 3px 0;
        height: 20px;
        vertical-align: top;
        cursor: pointer;
    }
    div.add-to-cart div.quantity input#add1:hover{ 
        background-color: #CCC;
        border: 1px solid #DDD;
    }
    div.add-to-cart div.quantity{
        margin-bottom: 5px;
        float: right;
    }
and that's it!

Monday, March 28, 2011

Magento Debugging Tips

Referenced from Inchoo

Snippet 1: Check if variable is object and of which class
<?php Zend_Debug::dump(get_class($this), 'get_class') ?>
<?php
/**
 * Once you do get_class you will get a class name.
 * With class name you can do something like
 * $this = new Mage_Page_Block_Html_Header();
 * then IDE will give you autocomplete on things like "$this->"
 *
 * Just remember to comment the out the
 * //$this = new Mage_Page_Block_Html_Header();
 * once you are done
 */
?>

Snippet 2: Do a basic dump of variable to see its "content"/value

<?php Zend_Debug::dump($this->debug(), 'debug') ?>

Snippet 3: Read the value of object properties/attributes

(Note that $_product var is just example, it can be any Magento/Varien object)

<?php Zend_Debug::dump($_product->getData('attribute_name')) ?> 

Snippet 4: Read the value of object properties/attributes

(Does the same thing as Snippet 3)

<?php Zend_Debug::dump($_product->getAttributeName()) ?>

Snippet 5: Compare the value of attribute/property to some other value

<?php if($_product->getSku() == 'sku-xxx-ppp-222'): ?>
    Ouput something only if product Sku is equal to 'sku-xxx-ppp-222'.
<?php endif; ?> 

Snippet 6: Loop trough Magento collection object

(Check if something is a collection, if we can iterate trough it)

<?php if($someVar instanceof Varien_Data_Collection): ?>
    
    <?php foreach($someVar as $k => $v): ?>
  • Some value: < ?php echo $v ?>

Tuesday, March 22, 2011

How to automate related products selection in Magento?

This mod does the following
  • fetch all the products in a category
  • dispaly them below the main picture in product view
  • no need to set the related products (if your products are within the same category)
  1. go to app/design/frontend/your-package/your-theme/template/catalog/list/related.phtml ( make a backup of this one )
  2. overwrite all the codes in your related.phtml with this one
<?php
$_product = $this->getProduct();
if ($_product) {
   // get collection of categories this product is associated with
   $categories = $_product->getCategoryCollection()
   ->setPage(1, 1)
   ->addFieldToFilter('parent_id',"2")
   ->load();

   // if the product is associated with any category
   if ($categories->count())
      foreach ($categories as $_category){
         $cur_category = Mage::getModel('catalog/category')->load($_category->getId());
         $prodCollection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($_category);
         Mage::getSingleton('catalog/product_status')
           ->addVisibleFilterToCollection($prodCollection);
         Mage::getSingleton('catalog/product_visibility')
           ->addVisibleInCatalogFilterToCollection($prodCollection);
         if($prodCollection->count() > 1) :
             ?><div class="related-product">
               <div class="block-title">
                 <h4><?php echo $this->__('More from this artist...') ?></h4>
               </div>
             <?php $products = Mage::getResourceModel('catalog/product_collection')
             ->addCategoryFilter($_category)
             ->addAttributeToSelect('small_image'); ?>
<ol class="mini-products-list" id="block-related">
 <div class="block-content">
<?php foreach ( $products as $productModel ){
$_product = Mage::getModel('catalog/product')->load($productModel->getId());
$width=100; $height=100;
$_imageUrl = $this->helper('catalog/image')->init($productModel, 'small_image')->resize($width, $height);
$currentUrl = $this->helper('core/url')->getCurrentUrl();                    //SPLIT THE URL FOR QUERY STRING<br />
$rel_product = explode( "?", $currentUrl); 
//SPLIT THE URL FOR CATEGORY
$cprod_url = explode( "/", $_product->getProductUrl());                    //ASSIGN THE STRIPPED URL TO A VARIABLE
$isyan = $cprod_url[0].'//'.$cprod_url[2].'/'.$cprod_url[4];                    //WE WILL HIDE THE PRODUCT THAT IS CURRENTLY BEING VIEWED FROM DISPLAYING ON THE RELATED PRODUCTS
if( $_product->getProductUrl() != $rel_product[0] && $isyan != $rel_product[0]){
?>
 <li class="item">
<a href="<?php echo $isyan ?>" class="product-image" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><img src=<?=$_imageUrl ?> width="<?=$width?>" height="<?=$height?>"/></a>
</li>
 <?php } 
}
?>
</div>
</ol>
</div>
<?php   endif; 
}
}
?>
Hope this helps! Godbless!

Wednesday, February 23, 2011

Magento - How to insert a custom tab in One Page Checkout?

I found a nice extension from Inchoo which will insert a customizable tab in Magento OnePage Checkout. So I used this extension and extended it a little bit to fit the requirements.

What I want to do is to add a Terms & Conditions tab before placing an order. So here's the code.
/home/donnafiera/magento/app/design/frontend/default/default/template/checkout/onepage/heared4us.phtml

<form id="co-heared4us-form" action="">
  <?php echo "I have read the <a href='".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."test.pdf' target='_Blank'>TERMS AND CONDITIONS</a>"; ?>
  <label><input id="chkaccept" type="checkbox" name="useraccept" value="yes" />&nbsp;Accept</label><br/>
</form>
<script type="text/javascript">
  function formValidation(oEvent) {
  oEvent = oEvent || window.event;
  var txtField = oEvent.target || oEvent.srcElement;
  var t1ck=true;
  if(!document.getElementById("chkaccept").checked ){ t1ck=false;}
    if(t1ck){document.getElementById("btnTerms").disabled = false; }
    else{document.getElementById("btnTerms").disabled = true; }
  }

window.onload = function () {
var btnTerms = document.getElementById("btnTerms");
var chkaccept=document.getElementById("chkaccept");
var t1ck=false;
document.getElementById("btnTerms").disabled = true;
chkaccept.onclick = formValidation;
}
</script> 
<div class="button-set">
<p class="required"><?php echo $this->__('* Required Fields') ?></p>
<div id="heared4us-buttons-container">
<button id="btnTerms" type="button" class="form-button right" onclick=" heared4us.save();"><span><?php echo $this->__('Continue') ?></span></button>
<span id="heared4us-please-wait" style="display:none;" class="opc-please-wait">
<img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" class="v-middle" alt="" /> &nbsp; <?php echo $this->__('Loading next step...') ?> &nbsp;
</span>
</div>
</div>

Sunday, February 6, 2011

Magento - How to create a special price page? (with new products first)

I've created a Magento site for a client who wants to have a special price page, wherein she could put products having special price/discounted price..
Requirements:
  • app/code/local/Mage/Catalog/Block/Product/Special.php
  • app/design/frontend/default/donna/template/catalog/product/special.phtml
  • Magento backend - CMS>Pages>create-a-special-price-page
Special.php
=========================================
<?php
class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_List
{
   function get_prod_count()
   {
      //unset any saved limits
      Mage::getSingleton('catalog/session')->unsLimitPage();
      return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 9;
   }// get_prod_count
   function get_cur_page()
   {
      return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;
   }// get_cur_page
   /**
    * Retrieve loaded category collection
    *
    * @return Mage_Eav_Model_Entity_Collection_Abstract
   **/
   protected function _getProductCollection()
   {
        $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
        $tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y'));
        $dateTomorrow = date('m/d/y', $tomorrow);
        $collection = Mage::getResourceModel('catalog/product_collection');
        $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
        $collection = $this->_addProductAttributesAndPrices($collection)
         ->addStoreFilter()
         ->addAttributeToSort('entity_id', 'desc') //THIS WILL SHOW THE LATEST PRODUCTS FIRST
         ->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
         ->addAttributeToFilter('special_to_date', array('or'=> array(0 => array('date' => true, 'from' => $dateTomorrow), 1 => array('is' => new Zend_Db_Expr('null')))), 'left')
         ->setPageSize($this->get_prod_count())
         ->setCurPage($this->get_cur_page());
        $this->setProductCollection($collection);
        return $collection;
   }// _getProductCollection
}// Mage_Catalog_Block_Product_New
?> 
==============================================

special.phtml
==============================================
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<div class="widget widget-new-products">
    <div class="widget-title">
        <h2><?php echo $this->__('Special Product') ?></h2>
    </div>
    <div class="widget-products">
    <?php $_columnCount = $this->getColumnCount(); ?>
        <?php $i=0; foreach ($_products->getItems() as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="products-grid">
        <?php endif ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image') ?>" width="195px" height="195px" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
                    <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>
                    <!-- ###### BRANDS EG. BY CHIC ON A MISSION ###### -->
                    <div class="product-brand"><?php echo $this->htmlEscape($_product->getextraline()) ?></div>
                    <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?> 
                    <?php echo $this->getPriceHtml($_product, true, '-widget-new-grid') ?>
                <div class="actions">
                    <?php if($_product->isSaleable()): ?>
                        <!-- <button type="button" title="<?php /* echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart')*/ ?></span></span></button>-->
                    <?php else: ?>
                        <!--<p class="availability out-of-stock"><span><?php // echo $this->__('Out of stock') ?></span></p>-->
                        <div class="out-of-stock-special"><img src="<?php echo $this->getSkinUrl('images/donna/soldout-overon.png') ?>" alt="uitverkocht" width="50px" /></div>
                    <?php endif; ?>
                    <?php /*<ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        <?php endif; ?>
                        <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                            <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                        <?php endif; ?>
                    </ul> */ ?>
                </div>
                </li>
        <?php if ($i%$_columnCount==0 || $i==count($_products)): ?>
        </ul>
        <?php endif ?>
        <?php endforeach; ?>
        <div class="toolbar-bottom">
            <?php // echo $this->getToolbarBlock()->setTemplate('catalog/product/list/ctoolbar.phtml')->toHtml(); ?>
        </div>
    </div>
</div>
<?php endif; ?>  
========================================

In the CMS Page that you created, click Design tab then in the Page layout>Layout update xml put this code..

<reference name="content">
   <block type="catalog/product_special" name="product_special" template="catalog/product/list.phtml">
       <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
              <action method="setDefaultDirection"><dir>desc</dir></action>
              <action method="setDefaultOrder"><field>entity_id</field></action>
              <block type="page/html_pager" name="product_list_toolbar_pager" />
       </block>
      <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
      <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
   </block>
</reference>
========================================

There you have it... Don't forget to put a special price, special-from-date and special-to-date in your products...
Reference: http://www.magentocommerce.com/boards/viewthread/16098/P15/ :kkrieger's post

Thursday, February 3, 2011

Magento product image switcher

Recently had a client who wants to display the more views thumbnail in the main picture when clicked. Then when the main picture is clicked, the main picture will be displayed via lightbox.
For the Image switcher: (replace the catalog/product/view/media.phtml content with these)
<?php
    $_product = $this->getProduct();
    $_helper = $this->helper('catalog/output');
    $_gallery = $this->getGalleryImages();
    $_resize = 265;
?>
<style type="text/css">
.product-img-box .more-views li.slide-current a{ border:2px solid #aaa; }
.product-img-box .product-image-zoom img { cursor: pointer; }
#slide-loader{ visibility:hidden; position:absolute; top:auto; left:auto; right:2px; bottom:2px; width: 25px; height: 25px; }
</style>
<script type="text/javascript">
function slide(url,num,gallery){
  if (typeof slide.loading == 'undefined') slide.loading = false;
    if(slide.loading) return false;
      var loader = new Image();
      $(loader).observe('load', function(){
         $('slide-loader').setStyle({'visibility':'hidden'});
         $('div.more-views li').each(function(el,i){
           (i==num) ? el.addClassName('slide-current') : el.removeClassName('slide-current');
         });
         var dummy = new Element('img', { src: url }).setOpacity(0);
         new Insertion.After('image', dummy);
         new Effect.Opacity(dummy, { duration:.5, from:0, to:1.0 });
         new Effect.Opacity($('image'), { duration:.5, from:1.0, to:0, 
         afterFinish: function(){
        $('image').writeAttribute('src',url).setOpacity(1).observe('click',function(e){
  Event.stop(e);
  popWin(gallery, 'gallery', 'width=300,height=300,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes'); 
  return false;
;})
dummy.remove();
slide.loading = false;
}
});
});
$('slide-loader').setStyle({'visibility':'visible'});
loader.src=url;
slide.loading = true;
return false;
}
</script>
<p class="product-image-zoom">
<?php
$_img = '<img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image')->resize($_resize).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" onclick="popWin(\''.$this->getGalleryUrl().'.\', \'gallery\', \'width=300,height=300,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes\'); return false;" />';
echo $_helper->productAttribute($_product, $_img, 'image')
?>
<img id="slide-loader" src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" />
</p>
<p class="a-center" id="track_hint"><?php echo $this->__('Click on above image to view full picture') ?></p>
<?php if (count($_gallery) > 0): ?>
<div class="more-views">
<h4><?php echo $this->__('More Views') ?></h4>
<ul>
<?php foreach ($_gallery as $_image): ?>
<li>
<a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->resize($_resize) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
One thing to note though. When the main picture is clicked, it will load the image in a popup window which is not beautiful.. I want to add a lightbox effects that will load the main picture when clicked.
================================================================
Update: achieved the thickbox lightbox integration. Refer to this site : www.room9.nl
Here's the same code from above but modified...
<?php
$_product = $this->getProduct();
$_helper = $this->helper('catalog/output');
$_gallery = $this->getGalleryImages();
$_resize = 350;
?>
<style type="text/css">
.product-img-box .more-views li.slide-current a{ border:2px solid #aaa; }
.product-img-box .product-image-zoom img { cursor: pointer; }
#slide-loader{ visibility:hidden; position:absolute; top:auto; left:auto; right:2px; bottom:2px; width: 25px; height: 25px; }
</style>
<script type="text/javascript">
function slide(url,num,gallery){
if (typeof slide.loading == 'undefined') slide.loading = false;
if(slide.loading) return false;
var loader = new Image();
$(loader).observe('load', function(){
$('slide-loader').setStyle({'visibility':'hidden'});
$('div.more-views li').each(function(el,i){
(i==num) ? el.addClassName('slide-current') : el.removeClassName('slide-current');
});
var dummy = new Element('img', { src: url }).setOpacity(0);
new Insertion.After('image', dummy);
new Effect.Opacity(dummy, { duration:.5, from:0, to:1.0 });
new Effect.Opacity($('image'), { duration:.5, from:1.0, to:0, 
afterFinish: function(){
$('image').writeAttribute('src',url).setOpacity(1).observe('click',function(){
$('swapper').href = url;
})
dummy.remove();
slide.loading = false;
}
});
});
$('slide-loader').setStyle({'visibility':'visible'});
loader.src=url;
slide.loading = true;
return false;
}
</script>
<p class="product-image-zoom">
<?php
$_img_a = '<a id="swapper" class="thickbox" rel="group" href="'.$this->helper('catalog/image')->init($_product, 'image').'" title="'.$this->htmlEscape($this->getImageLabel()).'">';
$_img_b = '<img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" /></a>';
?>
<?php echo $_helper->productAttribute($_product, $_img_a.$_img_b, 'image') ?>
<img id="slide-loader" src="<?php echo $this->getSkinUrl('images/lightbox/loading.gif') ?>" />
  </p>
<?php if (count($_gallery) > 0): ?>
<div class="more-views">
<h4><?php echo $this->__('More Views') ?></h4>
<ul>
<?php foreach ($_gallery as $_image): ?>
<li>
<a rel="group" href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(65); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>

Reference: http://inchoo.net/ecommerce/magento/magento-product-images-switcher/

Tuesday, January 18, 2011

Magento - Auto Store switcher using GEOIP

Prerequisites:
  • GEOIP (geoip.inc, geoip.dat etc)
  • Signup for an account in www.ipinfodb.com
  • Download the php class api HERE

  • 1. put the geoip files (preferably in a folder) in root directory
  • 2. edit the index.php of the root directory and replace these code
  • /* Store or website code */
    $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
    
    /* Run store or run website */
    $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
    
    Mage::run($mageRunCode, $mageRunType);
    
  • with these
//########### GEOIP ############//
$geoipPath = 'geoip.inc';
include($geoipPath);

$gi = geoip_open("GeoIP/GeoIP.dat",GEOIP_STANDARD);

$ip = $_SERVER['REMOTE_ADDR'];
$country_code = geoip_country_code_by_addr($gi, $ip);

if(strtoupper($country_code) != "NL"){
    $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'en';
    $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

    Mage::run($mageRunCode, $mageRunType);
}else{
    $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'nl';
    $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

    Mage::run($mageRunCode, $mageRunType);
}

Thursday, December 2, 2010

Magento - Custom Pagination

custom pagination

Ok so you want to have a different pagination.. that can be arranged.. :)

3 Files to edit:
  • styles.css
  • template/catalog/product/list/toolbar.phtml
  • template/page/html/pager.phtml

toolbar.phtml
<?php if($this->getCollection()->getSize()): ?>
<div class="toolbar">
<div class="pager">

<div class="limiter">
<label><?php echo $this->__('Toon:') ?></label>
<?php foreach ($this->getAvailableLimit() as  $_key=>$_limit): ?>
<a href="<?php echo $this->getLimitUrl($_key) ?>"><?php echo $_limit ?></a>
<?php endforeach; ?>
</div>
<?php echo $this->getPagerHtml() ?>

</div>
</div>


pager.phtml
<?php if($this->getCollection()->getSize()): ?>

<?php if($this->getUseContainer()): ?>
<div class="pager">
<?php endif ?>

<?php if($this->getShowAmounts()): ?>
<p class="amount">
<?php if($this->getLastPageNum()>1): ?>
<?php echo $this->__('Items %s to %s of %s total', $this->getFirstNum(), $this->getLastNum(), $this->getTotalNum()) ?>
<?php else: ?>
<strong><?php echo $this->__('%s Item(s)', $this->getTotalNum()) ?></strong>
<?php endif; ?>
</p>
<?php endif ?>

<?php if($this->getShowPerPage()): ?>
<div class="limiter">
<label><?php echo $this->__('Show') ?></label>
<select onchange="setLocation(this.value)">
<?php foreach ($this->getAvailableLimit() as  $_key=>$_limit): ?>
<option value="<?php echo $this->getLimitUrl($_key) ?>"<?php if($this->isLimitCurrent($_key)): ?> selected="selected"<?php endif ?>>
<?php echo $_limit ?>
</option>
<?php endforeach; ?>
</select> <?php echo $this->__('per page') ?>
</div>
<?php endif ?>

<!-- ############################ PAGER TOOLBAR ############################# -->

<?php if($this->getLastPageNum()>1): ?>
<div class="pages">
<ol>

<!-- ##################### PREVIOUS TOOLBAR ####################### -->
<div class="previous">
<?php if (!$this->isFirstPage()): ?>
<a class="previous-link" href="<?php echo $this->getPreviousPageUrl() ?>" title="<?php echo $this->__('Previous') ?>">
<?php if(!$this->getAnchorTextForPrevious()): ?>
<img src="<?php echo $this->getSkinUrl('images/i_pager-prev.gif') ?>" alt="<?php echo $this->__('Previous') ?>" class="v-middle" />
<?php else: ?>
<?php echo $this->getAnchorTextForPrevious() ?>
<?php endif;?>
</a>
<?php else: ?>
<span class="no-previous">

<?php echo $this->getAnchorTextForPrevious() ?>
</span>
<?php endif;?>
</div>

<?php if ($this->canShowFirst()): ?>
<li><a class="first" href="<?php echo $this->getFirstPageUrl() ?>">1</a></li>
<?php endif;?>

<?php if ($this->getCurrentPage() >= 4): ?>
<li><a class="first" href="<?php echo $this->getFirstPageUrl() ?>">1</a></li>
<li class="ellipse"> ... </li>
<?php endif; ?>

<?php if ($this->canShowPreviousJump()): ?>
<li><a class="previous_jump" title="" href="<?php echo $this->getPreviousJumpUrl() ?>">...</a></li>
<?php endif;?>

<?php foreach ($this->getFramePages() as $_page): ?>
<?php if ($this->isPageCurrent($_page)): ?>
<li class="current"><?php echo $_page ?></li>
<?php else: ?>
<li><a href="<?php echo $this->getPageUrl($_page) ?>"><?php echo $_page ?></a></li>
<?php endif;?>
<?php endforeach;?>


<?php if ($this->canShowNextJump()): ?>
<li><a class="next_jump" title="" href="<?php echo $this->getNextJumpUrl() ?>">...</a></li>
<?php endif;?>

<?php
$lastpage = $this->getLastPageNum();
$lastpage = $lastpage - 2;
?>

<?php if ($this->getCurrentPage() < $lastpage ): ?>
<li class="ellipse"> ... </li>
<li><a class="last" href="<?php echo $this->getLastPageUrl() ?>"><?php echo $this->getLastPageNum() ?></a></li>
<?php endif; ?>

<?php if ($this->canShowLast()): ?>
<li><a class="last" href="<?php echo $this->getLastPageUrl() ?>"><?php echo $this->getLastPageNum() ?></a><li>
<?php endif;?>

<!-- ##################### NEXT TOOLBAR ####################### -->
<div class="next">
<?php if (!$this->isLastPage()): ?>
<a class="next-link" href="<?php echo $this->getNextPageUrl() ?>" title="<?php echo $this->__('Next >') ?>">
<?php if(!$this->getAnchorTextForNext()): ?>
<img src="<?php echo $this->getSkinUrl('images/i_pager-next.gif') ?>" alt="<?php echo $this->__('Next') ?>" class="v-middle" />
<?php else: ?>
<?php echo $this->getAnchorTextForNext() ?>

<?php endif;?>
</a>
<?php else: ?>
<span class="no-next">
<?php echo $this->getAnchorTextForNext() ?>
</span>
<?php endif;?>
</div>
</ol>

</div>

<?php endif; ?>
<?php if($this->getUseContainer()): ?>
</div>
<?php endif ?>
<?php endif ?>
Style it with CSS and you can have a new pagination.. Godbless!

Wednesday, December 1, 2010

Magento - Layered Navigation Custom



If you want your layered navigation to be customized like the image above follow me... :)

We need to edit 3 files..
  • styles.css
  • template/catalog/layer/filter.phtml
  • template/catalog/layer/view.phtml

filter.phtml
<select onchange="setLocation(this.value)" class="layer-nav-homepage">
<option value="" selected="true">

<?php if($GLOBALS['filtername'] == "Category"): ?>
<span>Kunstenaars</span>
<?php else: ?>
<?php echo $GLOBALS['filtername']; ?>
<?php endif; ?>
</option>

<?php foreach ($this->getItems() as $_item): ?>
<?php if ($_item->getCount() > 0): ?>
<option value="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?>&nbsp;(<?php echo $_item->getCount() ?>)</option>
<!--<a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>-->
<?php else: echo $_item->getLabel() ?>
<?php endif; ?>


<?php endforeach ?>
</select>

Remarks:
The list was changed into <select> for dropdown, then a default (no value) option was placed - this will get the name of the filter.. eg. category, price and style..., then the option..


view.phtml
<?php if($this->canShowBlock()): ?>
<div class="block block-layered-nav">
<div class="block-title">
<span><?php echo $this->__('Filter kunst op: ') ?></span>
</div>
<div class="block-content">
<?php echo $this->getStateHtml() ?>
<?php if($this->canShowOptions()): ?>
<!--<p class="block-subtitle"><?php // echo $this->__('Shopping Options') ?></p>-->
<dl id="narrow-by-list">

<?php $_filters = $this->getFilters() ?>
<?php $i=0; ?>
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getItemsCount()): ?>

<?php $GLOBALS['filtername'] = $_filter->getName(); ?>

<!--<dt><?php // echo $this->__($_filter->getName()) ?></dt>-->
<dd><?php echo $_filter->getHtml() ?></dd>

<?php if($i==2): ?>
<?php else: ?>
<span> of </span>
<?php endif; $i++; ?>

<?php endif; ?>
<?php endforeach; ?>

</dl>
<script type="text/javascript">decorateDataList('narrow-by-list')</script>
<?php endif; ?>
</div>
</div>
<?php endif; ?>

Remarks:
The global var is for the filter name to be passed on the filter.phtml, then the condition if == 2 is for the OF... :)

Then to be able to put this on the homepage, you should enable isAnchor property of Default category... Also make the style attribute... That's IT! Hope this helps! Godbless!

Magento - Display all products in Homepage with pagination


A client asked to create a Magento shop with Art Gallery like functionality. What she want is to have a product list in the homepage having pagination. Let's get it on!

  • In the backend:
    Manage Categories > set the default category to anchor:yes, then assign all products in this category
  • CMS->homepage > put this snippet in the layout update xml

<!-- ########################## DISPLAY ALL PRODUCTS IN HOMEPAGE ############################ -->
<reference name="content">
<block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml"/>
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<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"/>
</block>
<action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
<update handle="page_two_columns_right" />
</reference>

Tuesday, November 23, 2010

Magento - Display Categories (with category images) in the homepage

<div class="top-home-category">
<?php 
/******** Don't know why I commented this
$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
$_imgHtml = '';

if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p>';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
****************************************/
?>

<?php // Iterate all categories in store
 $limit = 0;
$_helper    = $this->helper('catalog/output');
foreach ($this->getStoreCategories() as $_category): 
// If category is Active
if($_category->getIsActive()):
// Load the actual category object for this category
$cur_category = Mage::getModel('catalog/category')->load($_category->getId());
if ($_imgUrl = $cur_category->getImageUrl()){
$_imgHtml = '<img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($cur_category->getName()).'" title="'.$this->htmlEscape($cur_category->getName()).'"  width="105px" />';
$_imgHtml = $_helper->categoryAttribute($cur_category, $_imgHtml, 'image');
} 
?>
<div class="home-category">
<div class="linkimage">
<a href="<?php echo $this->getCategoryUrl($cur_category) ?>" style="border:none">
<?php echo $_imgHtml; ?>
</a>
</div>
<div class="category-link-container">
<a href="<?php echo $this->getCategoryUrl($cur_category) ?>">
<?php echo $_helper->categoryAttribute($cur_category, $cur_category->getName(), 'name') ?>
</a>
</div>
</div>

// Load a random product from this category
/*$products = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($cur_category)->addAttributeToSelect('small_image');
$products->getSelect()->order(new Zend_Db_Expr('RAND()'))->limit(1);
$products->load();
// This a bit of a fudge - there's only one element in the collection
$_product = null;
foreach ( $products as $_product ) {}
?>
<div class="home-category">
<div class="linkimage"><p><a href="<?php echo $this->getCategoryUrl($_category)?>">
<?php
if(isset($_product)):
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
<?php
endif;
?> </a></p>
</div>
<a href="<?php echo $this->getCategoryUrl($_category)?>"><?php echo $_category->getName()?></a>
</div>
*/?> <?php
$limit+=1;
endif;
if ($limit==8):
break;
endif;
endforeach;
?> 
</div>

Monday, November 22, 2010

Magento - Adding breadcrumbs to Homepage


1. Register the new module (we will call the module CMS and give the development company the name Acme):

In your magento\app\etc\modules directory create a file named Acme_All.xml with the following content:-

<?xml version="1.0"?>
<config>
  <modules>
    <Acme_Cms>
      <active>true</active>
      <codePool>local</codePool>
    </Acme_Cms>
  </modules>
</config>

2.  Register the module (which will be implemented in the class
Acme_Cms_Block_Page) as being responsible for rewrite-ing the cms/page
block

In a magento\app\code\local\Acme\Cms\etc directory (you will need to
create it) create a config.xml file with the following content:-

<?xml version="1.0"?>
<config>
  <global>
    <blocks>
      <cms>
        <rewrite>
          <page>Acme_Cms_Block_Page</page>
        </rewrite>
      </cms>
    </blocks>
  </global>
</config>

3. Change the original block logic (based on what is in app\code\core\Mage\Cms\Block\Page.php) to handle our CMS home page.

In a magento\app\code\local\Acme\Cms\Block directory create a file named Page.php with the content:-
<?php class Acme_Cms_Block_Page extends Mage_Cms_Block_Page{
protected function _prepareLayout(){
  $page=$this->getPage();
  //show breadcrumbs
  if(Mage::getStoreConfig('web/default/show_cms_breadcrumbs') && ($breadcrumbs=$this->getLayout()->getBlock('breadcrumbs'))
&& ($page->getIdentifier()!==Mage::getStoreConfig('web/default/cms_no_route'))){
  $breadcrumbs->addCrumb('home',array('label'=>Mage::helper('cms')->__('Home'),'title'=>Mage::helper('cms')->__('Go to Home Page'),'link'=>Mage::getBaseUrl()));
  if ($page->getIdentifier()!==Mage::getStoreConfig('web/default/cms_home_page')){
    $breadcrumbs->addCrumb('cms_page', array('label'=>$page->getTitle(), 'title'=>$page->getTitle()));
  }
}
  if($root=$this->getLayout()->getBlock('root')){
    $root->addBodyClass('cms-'.$page->getIdentifier());
  }
  if($head=$this->getLayout()->getBlock('head')){
    $head->setTitle($page->getTitle());
    $head->setKeywords($page->getMetaKeywords());
    $head->setDescription($page->getMetaDescription());
  }
}
}
Be sure that you have enabled breadcrumbs for CMS pages
[Config->Web->Default Pages->Show breadcrumbs for CMS pages =
Yes]


Reference: http://www.magentocommerce.com/boards/viewthread/49743/

Thursday, November 18, 2010

Magento - Embed Jquery Image Rotator

A client wants to have a javascript Image Rotator in her site that will dynamically fetch and display all the images inside the specified folder ( so that she can add and remove them any time she wants).. So I opted to use Jquery Framework to do the job...

here's the code I placed in catalog/navigation/getImage.phtml

<link rel="stylesheet" href="<?php echo $this->getBaseUrl().'jshowoff.css' ?>" type="text/css" media="screen, projection" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo $this->getBaseUrl().'jquery.jshowoff.min.js' ?>"></script>

<?php
/* This code will dynamically fetch all the images inside the specified folder
 * and display it using jquery
 * youngstownph@gmail.com
 * Incramind 2010
 */
       

    $currentCategory = '';

    $currentCategory = Mage::registry('current_category');
    if(!empty($currentCategory))
    $currentCategory = Mage::registry('current_category')->getName();


switch ($currentCategory)
{

    case "Sjaals":

        $imagePath = "media/banner/Sjaals";
        break;

    case "Riemen":

        $imagePath = "media/banner/Riemen";
        break;

    default:
      
        $imagePath = "media/banner/default";
        break;

}

if ($dir = opendir($imagePath))

{
    $images = array();
    while (($file = readdir($dir))!== false)
            {

        if ($file != "." && $file != ".." && $file != "Thumbs.db")
                    {
                      
                            $images[] = $file;
                     
                    }
            }
    closedir($dir);
}

echo '<div id="slidingFeatures">';
foreach($images as $image) {
    echo '<div><img src="';
    echo $this->getBaseUrl().$imagePath."/".$image;
    echo '" alt="'.$image.'" /></div>';
}
echo '</div>';

?>

<script type="text/javascript">
        $(document).ready(function(){ $('#slidingFeatures').jshowoff({
                effect: 'slideLeft',
                controlText:{play:'Play',pause:'Pause',previous:'<',next:'>'},
                hoverPause: false
        }); });
</script>

If you want to display the rotator in the homepage...
{{block type="catalog/navigation" name="homepage.slider" template="catalog/navigation/getImage.phtml"}}

Add this code in the catalog.xml if you want the rotator to appear in the catalog page..
<block type="catalog/category_view" name="catalog.slider1" as="slider1" template="catalog/navigation/getImage.phtml" />

Don't forget to create the appropriate folders in the media/banner...
Hope this helps! Godbless!

Tuesday, November 9, 2010

Magento - Add Thumbnail Image in Transaction email

A client requested adding product thumbnail images in the Order Confirmation Email that is sent after a customer order a product.. Without much ado here's the code...

<?php //added for sending image with order
$product = Mage::getModel('catalog/product')
->setStoreId($_item->getOrder()->getStoreId())
->load($_item->getProductId());
?>
<p align="center"><img src="<?php echo Mage::helper('catalog/image')->init($product, 'image')->resize(50); ?>" width="50" height="50" alt="" /></p>

add this snippet below <td align="left" valign="top" style="padding:3px 9px">

NOTE: Don't forget to allow Display of Image in your email client (mine is gmail)

Thursday, September 16, 2010

Display Brand Logo (attribute) of a product depending on the Brand Name

<!-- ##### CODE TO SET THE BRAND LOGO USING BRAND NAME ##### -->
<div class="product-brand-logo">
<?php $brandname = $_product->getbrand_name() ?>
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "brandlogo/" .$brandname . ".png"; ?>" />
</div>

I just fetched the brand name and put it inside a variable and then fetched the image using Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)

reference:
http://www.magentocommerce.com/boards/viewthread/9701/
http://activecodeline.com/retrieving-url-paths-in-magento

Friday, September 10, 2010

How to easily display Magento cms pages in the home page using Static blocks

  • display links of your cms pages within a static block
  • use footer.phtml as the container for all the static blocks that we'll create

Files to modify:
  • footer.phtml
  • page.xml (optional)
  • styles.css (for styling the blocks)

-------------------------------------------------------------------------------------



First go to your magento backend.

  • create a page in CMS/PAGES (then take note of the url key-> we'll use that in the static block)
  • then create a new static block in CMS/STATIC BLOCKS
  • in the create static block page - take note of the identifier (we'll use that for making our block appear at the home page)
  • now to insert a link of your cms page in the static block insert this code

<a href="{{store direct_url="url-key-from-the-cms-page"}}">Title-Of-The_link</a>

--------------------------------------------------------------------------------------

Modify the footer.phtml and put something linke this:

<div class="footer-links">
<div class="footer-block">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('bestellen')->toHtml() ?>
</div>
</div>

NOTE: Remember the identifier that I told you to take note? put that inside the setBlockId('identifier-here')
-------------------------------------------------------------------------------------

Modify the page.xml (optional)

if you want to clear the contents of the footer just comment out the <blocks> inside the main <block>

<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 type="page/template_links" name="bestellen" as="bestellen" template="page/template/bestellen.phtml"/>-->
</block>

--------------------------------------------------------------------------------------
you can style your blocks by giving it a class and defining the class in styles.css

We're done! Hope this helps!

Thursday, September 9, 2010

Display Categories in the Home page

  • Display Categories in the Home page
  • Display a random product's picture with the category name
  • It can only fetch the 1st level category

-----------------------------------------------------------------------------------------------------
/* PUT THIS CODE IN CATALOG/CATEGORY/LIST.PHTML (create it if not present) */

<?php // Iterate all categories in store
    $limit = 0;
    $_helper    = $this->helper('catalog/output');
    foreach ($this->getStoreCategories() as $_category):

        // If category is Active
        if($_category->getIsActive()):


            // Load the actual category object for this category
            $cur_category = Mage::getModel('catalog/category')->load($_category->getId());

            if ($_imgUrl = $cur_category->getImageUrl()){

                $_imgHtml = '<img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($cur_category->getName()).'" title="'.$this->htmlEscape($cur_category->getName()).'"  width="105px" />';
                $_imgHtml = $_helper->categoryAttribute($cur_category, $_imgHtml, 'image');
            } ?>
             <div class="home-category">
                <div class="linkimage">
                    <a href="<?php echo $this->getCategoryUrl($cur_category) ?>" style="border:none">
                    <?php echo $_imgHtml; ?>
                    </a>
                </div>
                <div class="category-link-container">
                <a href="<?php echo $this->getCategoryUrl($cur_category) ?>">
                       <?php echo $_helper->categoryAttribute($cur_category, $cur_category->getName(), 'name') ?>
                </a>
                </div>
            </div>
<?php
           $limit+=1;
        endif;

        if ($limit==8):
            break;
        endif;

    endforeach;
?>

----------------------------------------------------------------------------------------------------------
/* PUT THIS CODE IN THE CMS/PAGES/HOME*/
/* IF YOU WANT TO HARDCODE IT PLACE THIS IN LAYOUT/PAGE.XML -> "Custom page layout handles" AREA */

{{block type="catalog/navigation" name="catalog.category" template="catalog/category/list.phtml"}}
----------------------------------------------------------------------------------------------------------


Reference

Friday, September 3, 2010

IE Conditional Comment

This is a conditional comment. This is used to add extra tags if ever your webpage is opened in IE6 browser.

<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="js/shadowbox3/shadowbox-ie6.css">
<![endif]-->

More Info