首頁  >  問答  >  主體

無法在我的建立模組中顯示類別圖像

我想在我自己的模組中顯示caregory映像,所以我創建了一個模組和frontend/templates/category-section.phtml,這是程式碼,我的問題是來源圖像是空的,它在我的模組中傳回null建立頁面,所有其他類似的屬性都可以正常運作

我在管理面板中上傳了圖像,當我單擊 a 標籤時,它會正確返回帶有圖像的類別頁面,但僅在我顯示類別和圖像中,圖像未顯示

此處的圖像未顯示

如果我點擊任何一個,URL 和圖像都存在於此處,但在新模組中則不存在

<?php echo $category->getName() ?>
<section class="section-holder">
    <div class="all-categories">
        <p class='category-text'>categories</p>
        <div class='categories-flex'>
            <?php
            $categoryHelper = $this->helper('Magento\Catalog\Helper\Category');
            $outputhelper = $this->helper('Magento\Catalog\Helper\Output');


            foreach ($categoryHelper->getStoreCategories() as $category) :

            ?>
                <a href="<?php echo $categoryHelper->getCategoryUrl($category) ?>">
                    <div class='child-category'>
                        <div>
                            <img style="background-image: url('<?= $category->getImageUrl(); ?>');" alt="">
                        </div>

                        <p> <?php echo $category->getName() ?></p>
                    </div>
                </a>
            <?php
            endforeach;
            ?>
        </div>
    </div>
</section>

#
P粉731977554P粉731977554209 天前524

全部回覆(1)我來回復

  • P粉458725040

    P粉4587250402024-02-27 13:13:04

    方法getStoreCategories不會載入類別的圖片。它只載入活動模組的 catalog_attributes.xml 檔案中聲明的屬性。
    您可以嘗試透過在自己的模組中建立此檔案來將圖像屬性新增至此清單

    etc/catalog_attributes.xml

    #<?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd">
        <group name="catalog_category">
            <attribute name="image"/>
        </group>
    </config>

    完成後清除快取。

    回覆
    0
  • 取消回覆