分类法自定义现场图像未显示

发布于 2025-01-19 02:01:38 字数 1151 浏览 0 评论 0原文

我想在主页上循环显示分类自定义字段图像 “开发商”是分类名称 “developer_logo”是图像字段 slug 我使用的代码仅显示名称,但图像未显示

 <?php      
        $terms = get_terms( array( 'taxonomy' => 'developers', 'hide_empty' => false ) );
        $image = get_field('developer_logo');
        foreach ( $terms as $term ) : ?>
        
            <div class="col-lg-4 col-md-6">
                <div class="product product-zoom product--card">
                    <div class="product__thumbnail">
                        <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo $term->name; ?>">
                    </div>
                    <div class="product-desc">
                        <h4 class="text-center mb-2"><?php echo $term->name; ?></h4>
                    </div>
                </div>
            </div>              
        
        <?php
        endforeach
        ?>
            

在此处输入图像描述 在此处输入图像描述

我只想显示分类自定义字段的图像

I want to show taxonomy custom field images on loop on the home page
"developers" is taxonomy name
and "developer_logo" is image field slug
I used that code only name is showing but image is not showing

 <?php      
        $terms = get_terms( array( 'taxonomy' => 'developers', 'hide_empty' => false ) );
        $image = get_field('developer_logo');
        foreach ( $terms as $term ) : ?>
        
            <div class="col-lg-4 col-md-6">
                <div class="product product-zoom product--card">
                    <div class="product__thumbnail">
                        <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo $term->name; ?>">
                    </div>
                    <div class="product-desc">
                        <h4 class="text-center mb-2"><?php echo $term->name; ?></h4>
                    </div>
                </div>
            </div>              
        
        <?php
        endforeach
        ?>
            

enter image description here
enter image description here

This is how it is showing

I just want to show the images of taxonomy custom field

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[旋木] 2025-01-26 02:01:39
**In the below code, i have added the term Id as second parameter in get_field() function to get image URL & replaced the $image variable from outside of loop to inside the foreach loop.** 
        
        <?php
       $terms = get_terms(array(
          'taxonomy' => 'developers',
          'hide_empty' => false
       ));
       foreach ($terms as $term) {
          $image = get_field('developer_logo', $term->id); ?>
          <div class="col-lg-4 col-md-6">
             <div class="product product-zoom product--card">
                <div class="product__thumbnail">
                   <img src="<?php echo $image; ?>" alt="<?php echo $term->name;?>">
                </div>
                <div class="product-desc">
                   <h4 class="text-center mb-2"><?php echo $term->name;?></h4>
                </div>
             </div>
          </div>  
          <?php
          }
    ?>
**In the below code, i have added the term Id as second parameter in get_field() function to get image URL & replaced the $image variable from outside of loop to inside the foreach loop.** 
        
        <?php
       $terms = get_terms(array(
          'taxonomy' => 'developers',
          'hide_empty' => false
       ));
       foreach ($terms as $term) {
          $image = get_field('developer_logo', $term->id); ?>
          <div class="col-lg-4 col-md-6">
             <div class="product product-zoom product--card">
                <div class="product__thumbnail">
                   <img src="<?php echo $image; ?>" alt="<?php echo $term->name;?>">
                </div>
                <div class="product-desc">
                   <h4 class="text-center mb-2"><?php echo $term->name;?></h4>
                </div>
             </div>
          </div>  
          <?php
          }
    ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文