【问题标题】:ACF Checkbox - check box output imageACF Checkbox - 复选框输出图像
【发布时间】:2019-03-05 23:51:03
【问题描述】:

我试图让 ACF 复选框在选中时输出图像。这是我所拥有的

<?php if (in_arry('The Home Depot', ("retailers"))) { echo '<img src="' . echo get_stylesheet dirctory_url() . '/images/thehomedepot.jpg'" alt="The Home Depot"> } elseif(in_arry('True Value', ("retailers"))) { echo '<img src="' . echo get_stylesheet dirctory_url() . '/images/truevalue.jpg'" alt="The Home Depot"> }else {

} ?>

retailers 是复选框字段,The Home Depot 和 True Value 是复选框。

提前致谢

【问题讨论】:

    标签: arrays wordpress image checkbox advanced-custom-fields


    【解决方案1】:
    <?php $retailers = get_field('retailers'); ?>
    
    <?php if( in_array('The Home Depot', $retailers )): ?>
        <img src="<?php echo get_stylesheet_dirctory_url(); ?>/images/thehomedepot.jpg" alt="The Home Depot">
    <?php endif; ?>
    

    请确保“The Home Depot”是复选框的值,而不仅仅是标签。使用 print_r($retailers); 输出数组这样你就可以看到你正在使用什么。

    【讨论】:

    • 这是我打印出零售商数组 ([0] => The Home Depot ) 时得到的结果 当我在上面添加代码时,由于某种原因它不会显示图像有什么想法吗?跨度>
    • 我刚刚注意到,在复制您的部分代码时,get_stylesheet_directory_url() 中缺少下划线 - 是这个问题吗?
    • 我不确定发生了什么我添加了对我来说看起来正确但没有显示图像甚至 div 的代码。
    • 也许尝试将字段值设置为“the-home-depot”?
    【解决方案2】:

    如果有人需要帮助,这就是我想出的让一切正常工作的方法。

    <?php if(in_array('thd', get_field('retailers') ) ) {
                echo '<li>';
                echo '<a href="';
                echo get_field('the_home_depot_product_url');
                echo '">';
                echo '<img src="../thehomedepot.jpg" alt="The Home Depot" />';
                echo  '<h3>The Home Depot</h3>';
                echo '</a>';
                echo '</li>';
            } ?>
    

    【讨论】:

      猜你喜欢
      • 2022-10-02
      • 1970-01-01
      • 2021-04-13
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 2015-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多