Grigoras Cosmin
Grigoras Cosmin

Reputation: 11

How to get page title by id in magento?

I need to display a list of pages in the header (their title) and when the user clicks on a page title he will be directed to the corresponding page.

How can I obtain the title and the permalink of a page, knowing the page Id? For now i wrote select page_id, title from cms_page here page_id in (6,7,8).

But isn't there a method in Magento that I can use to obtain this information?

Upvotes: 1

Views: 4466

Answers (2)

Andy F.
Andy F.

Reputation: 11

To get the CMS page's title from its id:

$page_title = Mage::getModel('cms/page')->load($page_id)->getTitle();

To get the CMS page's url from its id:

$page_url = Mage::helper('cms/page')->getPageUrl($page_id);

Upvotes: 1

Gowri
Gowri

Reputation: 16835

How to add cms page in top link?

Goto page.xml(layout/page.xml) find topLinks then modify

<block type="page/template_links" name="top.links" as="topLinks"/>

to

 <block type="page/template_links" name="top.links" as="topLinks">
   <action method="addLink" translate="label title"><label>Your page </label><url>your-page</url><title>YOUR PAGE</title><prepare/><urlParams/><position>80</position></action>

  </block> 

How to get particular page URL using page id ?

use this refer here

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

Adding Dynamically cms pages to top link

This one can collect all cms pages

$cms = Mage::getModel('cms/page')->getCollection();  

To get store id use bellow one.

$store_id = Mage::app()->getStore('default')->getCode();
$cms->addStoreFilter($store_id);
$cms->load();

Then you can extract it as you want.Here More information

Upvotes: 1

Related Questions