How to get Current page url in magento.

April 19, 2011 | In: Magento

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 :) 
*/

/*
* 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
?>

Comments

comments

Powered by Facebook Comments

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

 

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Inquire Now
  • captcha
 

PSD to MagentoAdvertisementAdvertisementAdvertisement


Latest comments

  • None found