Friday 11 October 2013

Create A Sticky Menu In Magento

Add Following in code in template/catalog/navigation/top.phtml

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>

<style type="text/css">
.sticky {
    position: fixed;
    width: 100%;
    left: 0;
    top: 0;
    z-index: 100;
    border-top: 0;
}
</style>

<script type="text/javascript">
                       jQuery(document).ready(function() {
                       var stickyNavTop = jQuery('.nav-container').offset().top;
               var stickyNav = function(){
                var scrollTop = jQuery(window).scrollTop();
                if (scrollTop > stickyNavTop) {
                    jQuery('.nav-container').addClass('sticky');
                } else {
                    jQuery('.nav-container').removeClass('sticky');
                }
            };

            stickyNav();
            jQuery(window).scroll(function() {
                stickyNav();
            });
        });
             
</script>

Monday 7 October 2013

Check If Home Page, CMS Page Or Any Other Page In Magento.

To check for any other cms page just replace ‘home’ in
the if condition to the identifier of the page you want to check.

< ?php
$route = Mage::app()->getRequest()->getRouteName();
$id = Mage::getSingleton('cms/page')->getIdentifier();
if($route == 'cms' && $id == 'home') {
    echo 'Homepage!';
}
?>

The code shown below checks for cart page. Change the if condition for any other page.

< ?php
$request = $this->getRequest();
$module = $request->getModuleName();   
$controller = $request->getControllerName();   
$action = $request->getActionName();   
if($module == 'checkout' && $controller == 'cart' && $action == 'index'):   
    echo "Cart page"
endif;
?>