久久久久久久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看片免费 | 精品免费| 色网站在线免费观看 | 日本三级全黄三级三级三级口周 | 国产成人免费在线观看 | 婷婷五月色综合 | 九九久久国产 | 欧美视频第三页 | 精品国产第一区二区三区 | 亚州成人| 亚洲成人日韩 | www在线| www.国产精 | 91麻豆产精品久久久久久 | 国产精品高潮呻吟久久 | 国产免费福利 | 亚洲精品成人免费 | 久久精品久久精品久久精品 | 国产精品免费在线 | 成人精品一区亚洲午夜久久久 | 久久精品亚洲精品国产欧美 | 日韩三级 | av黄色国产 | 国产精品久久久久久久久久久久午夜片 | 成人免费网站www网站高清 | 在线色网站 | 国产精品成人久久久久 | 日韩精品无码一区二区三区 | 日朝毛片| 国产精品国产三级国产aⅴ中文 |