久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Magento - 您如何將無限 CMS 靜態塊(具有特定“標識

Magento - How do you return results of unlimited CMS Static blocks (with certain quot;Identifierquot;) to a CMS Page(Magento - 您如何將無限 CMS 靜態塊(具有特定“標識符)的結果返回到 CMS 頁面) - IT屋-程序員軟件開發
本文介紹了Magento - 您如何將無限 CMS 靜態塊(具有特定“標識符")的結果返回到 CMS 頁面的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

快速概覽:我正在嘗試將一組特定靜態塊的結果返回到一個 phtml 文件(然后從 cms 頁面調用該文件)) 在 Magento 中.

注意:我一直在谷歌上搜索,有些答案讓我比其他答案更接近,但我嘗試過的任何東西似乎都沒有 100% 有效?

詳情:

我已經有一組特定的靜態塊,它們都以 testimonial- 的標識符開頭.例如,每個靜態塊是這樣的:testimonial-1testimonial-2testimonial-3等等.我的開發站點上總共有 5 個(更多在實時站點上,但在此處無關緊要).

我有一個 CMS 頁面,其中包含 name.phtml 文件中的代碼(我的 phtml 文件的位置在這里:app/design/frontend/[包]/[模板]/模板/頁面/):

{{block type="core/template" template="page/name.phtml" title="Others Say:" identifier="testimonial-"}}

這是我的 .phtml 文件代碼:

getCollection()->addFieldToFilter('identifier', array('like'=>'testimonial'.'%'))->addFieldToFilter('is_active', 1);//獲取計數$blockCount = $collection->count();echo '塊計數:'.$blockCount .'<br/>';//僅用于測試$blockNum = 1;foreach($collection as $key => $value){$_blockId = $this->getIdentifier();$block_ID = $_blockId .$blockNum;回聲鍵:".$key .——".塊ID:".$block_ID ."<br/>";$blockNum++;}$_block = $this->getLayout()->createBlock('cms/block')->setBlockId($block_ID);如果($_block):?><div class="block block-testimonial"><div class="block-title"><strong><?php echo $this->getTitle();?></strong>

<div class="block-content"><?php echo $_block->toHtml();?>

循環 foreach($collection as $key => $value) 打印出這個:

Key: 27 - 區塊 ID: testimonial-1鍵:28 - 區塊 ID: testimonial-2鍵:29 - 區塊 ID:testimonial-3鍵:30 - 區塊 ID: testimonial-4鍵:31 - 區塊 ID:testimonial-5

哪個好.

然而,唯一回顯的塊是最后一個塊 (testimonial-5).由于我試圖列出所有推薦塊,我如何將每個塊ID回顯到頁面?

放輕松,我是 php 的初學者.

解決方案

您沒有在 foreach 循環內打印塊.解決方法:將}括號移到粘貼代碼的末尾

$blockNum = 1;foreach($collection as $key => $value){$_blockId = $this->getIdentifier();$block_ID = $_blockId .$blockNum;回聲鍵:".$key .——".塊ID:".$block_ID ."<br/>";$blockNum++;$_block = $this->getLayout()->createBlock('cms/block')->setBlockId($block_ID);如果 ($_block) : ?><div class="block block-testimonial"><div class="block-title"><strong><?php echo $this->getTitle();?></strong>

<div class="block-content"><?php echo $_block->toHtml();?>

<?php萬一;}

我認為在 Magento Connect 上有一些推薦模塊,它們正在做你想要的工作.另一方面,如果您正在尋找簡單"的解決方案,或者您正在嘗試使用 Magento,那么這種方法是否可行.

Quick Overview: I am trying to return results from a specific set of static blocks to a phtml file (which is then called on from a cms page) in Magento.

Note: I've been searching all over google and some answers get me closer than others but nothing I've tried seems to work 100%?

Details:

I already have a set of specific static blocks that all start with an identifier of testimonial-. For example, each static block is like this: testimonial-1, testimonial-2, testimonial-3 and so on. I have a total of 5 on my dev site (more on live site but that is no consequence here).

I have a CMS Page with code pulling in the name.phtml file (location of my phtml file is here: app/design/frontend/[package]/[template]/template/page/):

{{block type="core/template" template="page/name.phtml" title="Others Say:" identifier="testimonial-"}}

Here is my code for the .phtml file:

<?php
    // add the collection with filters
$collection = Mage::getModel('cms/block')->getCollection()
    ->addFieldToFilter('identifier', array('like'=>'testimonial'.'%'))
    ->addFieldToFilter('is_active', 1);

// get the count
$blockCount = $collection->count();
    echo 'Block Count: ' . $blockCount . '<br />'; // just for testing

$blockNum = 1;
foreach($collection as $key => $value){
    $_blockId = $this->getIdentifier();
    $block_ID = $_blockId . $blockNum;
    echo "Key: " . $key . " - " . "Block ID: " . $block_ID . "<br />";
    $blockNum++;
}

$_block = $this->getLayout()->createBlock('cms/block')->setBlockId($block_ID);

if ($_block) :
?>
<div class="block block-testimonial">
<div class="block-title">
    <strong><?php echo $this->getTitle(); ?></strong>
</div>
<div class="block-content">
<?php echo $_block->toHtml(); ?>
</div>

The loop foreach($collection as $key => $value) prints out this:

Key: 27 - Block ID: testimonial-1
Key: 28 - Block ID: testimonial-2
Key: 29 - Block ID: testimonial-3
Key: 30 - Block ID: testimonial-4
Key: 31 - Block ID: testimonial-5

Which is good.

However, the only block that is echoed is the last block (testimonial-5). Since I'm trying to list out all the testimonial blocks, how can I echo out each block id to the page?

Go easy on me, I'm a beginner at php.

解決方案

You are not printing block inside foreach loop. Solution: move } parenthesis to the end of pasted code

$blockNum = 1;
foreach($collection as $key => $value){
    $_blockId = $this->getIdentifier();
    $block_ID = $_blockId . $blockNum;
    echo "Key: " . $key . " - " . "Block ID: " . $block_ID . "<br />";
    $blockNum++;    

    $_block = $this->getLayout()->createBlock('cms/block')->setBlockId($block_ID);

    if ($_block) : ?>
        <div class="block block-testimonial">
            <div class="block-title">
                <strong><?php echo $this->getTitle(); ?></strong>
            </div>
        <div class="block-content">
        <?php echo $_block->toHtml(); ?>
        </div>
    <?php 
    endif;
}

I think that on Magento Connect are some Testimonial Modules, that are doing job you want. On the other hand, if you are looking for 'simple' solution or if you are trying to play with Magento, is this approach ok.

這篇關于Magento - 您如何將無限 CMS 靜態塊(具有特定“標識符")的結果返回到 CMS 頁面的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 亚洲91视频 | 亚洲精品一 | 91毛片在线看 | 人人精品| 精品久久久久一区二区国产 | 久在线| 毛片视频网址 | 美女在线视频一区二区三区 | 在线电影日韩 | 日韩在线免费 | 99爱国产| 国产成人免费视频 | 国产成年人小视频 | 成人免费影院 | 欧美一区二区三区免费在线观看 | 性xxxxx | 精品一二三 | 亚洲网站观看 | 成人在线欧美 | 国产在线拍偷自揄拍视频 | 亚洲444kkkk在线观看最新 | 日本一区二区三区视频在线 | 精品国产一区二区三区免费 | 三级免费网 | 蜜桃视频在线观看免费视频网站www | 成人自拍视频网站 | 视频在线观看一区二区 | 一区二区高清 | 久久久久中文字幕 | 鲁视频| 久久久精品一区 | 美女中文字幕视频 | 日韩av在线免费 | 九九九视频在线 | 91精品在线播放 | 国产a一区二区 | 国产精品视频在线观看 | 国产精品久久久久久久久久久久久久 | 欧美日韩国产精品一区二区 | 中文字幕 在线观看 | 99久久国产 |