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



1 Response to Check home page URL in magento

Avatar

_______ __ ____ _ ___________

March 9th, 2013 at 1:53 am

hello there and thank you for your info _ I’ve certainly picked up anything new from right here. I did however expertise several technical points using this web site, as I experienced to reload the website many times previous to I could get it to load correctly. I had been wondering if your web hosting is OK? Not that I’m complaining, but slow loading instances
times will often affect your placement in google and
can damage your quality score if ads and marketing with Adwords.
Well I am adding this RSS to my email and can look out
for much more of your respective exciting content.
Ensure that you update this again very soon.

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>