magento 获取 pages/Static Block 内容 Get Pages/Static Block in Magento

1. pages

 

Sometimes, you want to use information like title or content from a CMS page (or multiple CMS pages) in another page. For example, you want to show a part of “Welcome” page in homepage. How can you do the task?

 

Today I will show you that how you can use CMS pages in another page.

 

To use information of a CMS page in another page, you will need the identifier (URL key) of this CMS page. Then in the page you want to use the information, put some codes as following:

$aCmsPage = Mage::getModel('cms/page')->load('URL-key-of-this-page', 'identifier');
$theTitle = $aCmsPage->getTitle();
$theContent = $aCmsPage->getContent();
 

Then you can use this title and content anywhere you want!

 

To get information from multiple CMS pages, we need to use CMS page collection:

$collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());
$collection->getSelect()->where('is_active = 1'); // use the filter in the case you want to get only enabled CMS pages.
foreach ($collection as $page) {
    $theIdentifier = $page->getIdentifier();
    $theTitle = $page->getTitle();
    $theContent = $page->getContent();
    ....// use these like you want!
}
 

Thats it ! Let try and enjoy!

 

from: http://miragedesign.net/newss/magento-use-cms-page-in-another-page/

 

2. static block

 

Magento has made it really easy to get Static Content from within a CMS page with the use of widgets, but say you’re developing a custom theme, you may want to call a static block programmatically in a Magento theme in which case there are a few methods of doing so…

 

The first is quick and easy to drop into a Magento theme, but only gets the static block content:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('indentifer')->toHtml() ?>
 

Where, by calling the static block model, you can then get all fields associated with that block such as the static block title

<?php
$block = Mage::getModel('cms/block')->load('identifier');
echo $block->getTitle();
echo $block->getContent();
?>
 

Add a CMS Static Block to a page: 

Within Magento:

{{block type="cms/block" block_id="identifier"}}

 

You want add static Block in xml file inside :

  <block type="cms/block" name="BLOCK_NAME" after="cart_sidebar">
    <action method="setBlockId"><block_id>IDENTIFIER</block_id></action>
  </block>
 

Hope this helps you with static blocks in your custom magento theme. Happy coding!

 

 

from: http://thinkclay.com/technology/get-static-block-in-magento

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值