Get Current page url in magento or you can find catalog url using below code.
With the help of this code you can easily find
current page url in magento
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php $current_page = '' ; /* * Check to see if its a CMS page * if it is then get the page identifier */ if (Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms' ): $current_page = Mage::getSingleton( 'cms/page' )->getIdentifier(); endif ; /* * If its not CMS page, then just get the route name */ if ( empty ( $current_page )): $current_page = Mage::app()->getFrontController()->getRequest()->getRouteName(); endif ; /* * What if its a catalog page? * Then we can get the category path :) */ /* * Or you can check all values * $current_page_array = Mage::registry('current_category'); * $current_page_array['url_path'] */ if ( $current_page == 'catalog' ): $current_page = 'path-' . preg_replace( '#[^a-z0-9]+#' , '-' , strtolower (Mage::registry( 'current_category' )->getUrlPath())); endif ; ?> |
Also if you want Full Current Page URL in Magento you can do so with this one line.
1 2 3 | <?php $currentUrl = $this ->helper( 'core/url' )->getCurrentUrl(); ?> |
Another way to get current url
1 2 3 4 5 6 7 8 9 10 | <?php $urlRequest = Mage::app()->getFrontController()->getRequest(); $urlPart = $urlRequest ->getServer( 'ORIG_PATH_INFO' ); if ( is_null ( $urlPart )) { $urlPart = $urlRequest ->getServer( 'PATH_INFO' ); } $urlPart = substr ( $urlPart , 1 ); $currentUrl = $this ->getUrl( $urlPart ); ?> |
Also you can check current page or catalog page is product page or not with “Mage::registry”.
1 2 3 4 5 6 | <?php $onCatalogFlag = false; if (Mage::registry( 'current_product' )) { $onCatalogFlag = true; } ?> |
And also try to something like below code
1 2 3 4 5 | <?php echo $this ->getRequest()->getControllerName(); if ( $this ->getRequest()->getControllerName()== 'product' ) //do something if ( $this ->getRequest()->getControllerName()== 'category' ) //do others ?> |
Justwebdevelopment can also help you in...
Magento Development | PSD To Magento | Magento Theme Development | Magento Development Services
Magento Development | PSD To Magento | Magento Theme Development | Magento Development Services