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
<?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 <img src="http://www.justwebdevelopment.com/blog/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley"> */ /* * 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.
<?php $currentUrl = $this->helper('core/url')->getCurrentUrl(); ?>
Another way to get current url
<?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”.
<?php $onCatalogFlag = false; if(Mage::registry('current_product')) { $onCatalogFlag = true; } ?>
And also try to something like below code
<?php echo $this->getRequest()->getControllerName(); if($this->getRequest()->getControllerName()=='product') //do something if($this->getRequest()->getControllerName()=='category') //do others ?>
近期评论