Gowri
Gowri

Reputation: 16835

How to get particular page URL in magento

I would like to get a page's URL key in Magento.

For example, I have a CMS page called "What's New" with the identifier (or URL key) "whats_new". Its correct URL is therefore http://mysite.com/whats_new

Currently I use this code to echo its location:

<?php echo Mage::getBaseUrl();?>whats_new

I feel it's bad practice because its identifier (or URL key) is administrable; if its URL key or identifier changes then the link will break. What is the proper way to echo its dynamic URL key? Perhaps something similar to Wordpress's get_permalink('10')?

Upvotes: 23

Views: 57481

Answers (7)

Josh
Josh

Reputation: 2820

I think this will do what you want:

<?php echo Mage::helper('cms/page')->getPageUrl( $pageId ) ?>

Replace $pageId with the correct id for the page you are linking to and it should work.

Upvotes: 41

tungpksa
tungpksa

Reputation: 31

You shoud use

{{store direct_url="whats_new/"}}

<?php echo $this->getUrl('whats_new');?>

Upvotes: 0

Bikram Pahi
Bikram Pahi

Reputation: 1183

In CMS Page

{{store _direct="url_key"}}

If you want in .phtml file then

<?php echo Mage::helper('cms/page')->getPageUrl('url_key') ?>

Upvotes: 5

sandip.vaghasiya
sandip.vaghasiya

Reputation: 165

It is also possible to retrieve the CMS page URL using the page identifier like,

<?php echo Mage::helper('cms/page')->getPageUrl('cms_page_identifier') ?>

Upvotes: 1

user3092275
user3092275

Reputation:

You shoud use <?php echo Mage::getUrl('page-url.html); ?>

Upvotes: 9

Tuong Le
Tuong Le

Reputation: 19230

Mage::getUrl(null, array('_direct' => $page->getIdentifier()));

Upvotes: 2

Anton S
Anton S

Reputation: 12750

Try this

<?php echo $this->getUrl('whats_new');?>

If you need to add url key dynamically then

<?php echo $this->getUrl($yourDynamicVariable);?>

of course you must implement the features that you need to fill the variable if url key is changed

Upvotes: 19

Related Questions