dongzong8110 2016-08-15 17:31
浏览 23
已采纳

高级自定义字段语法错误

I am editing a wordpress theme to add two fields to a slider plugin. I am using advanced custom fields to do this since I don't know PHP too well.

added customheader-img and big-descrip

$videobg_container .= '
<li>
  <div class="slide-container container text-'.$videobg_alignment.'">
    <div class="slide-content page-scroll" style="vertical-align:'.$videobg_vertical_alignment.';">
      <div class="customheader-img">$image = get_field('.$custom_header_image.');</div>
      '.$videobg_description.$videobg_title.$button1.'
      <div class="big-descrip" <?php the_field( 'Subtext'); ?></div>
    </div>
  </div>
</li>'; }

The code above spits out a syntax error. If I change the single quotes to double quotes ('Subtext') to ("Subtext") it doesn't error out but the content I add to the custom field doesn't show up.

Any ideas what I can do here?

Thanks!

</div>
  • 写回答

2条回答 默认 最新

  • douzhicui2209 2016-08-15 17:55
    关注

    To get Image field using ACF

    $image = get_field('image');
    

    Use print_r($image); and see to that there are multiple dimensions of the image uploaded and you could display based on the key values of the array // each image contains a custom field called 'link'

    $link = get_field('link', $image['ID']);
    

    At last you can have the image as <?php echo $image['url']; ?>

    To get the text or some other contents from ACF

    $variable = get_field('field_name');
    

    Another Important thing is that you have to use render of the variable to print the image that you have obtained Usage of print_r() will lead us to display the image as per our resolutions.

    For more documentation visit: https://www.advancedcustomfields.com/resources/image/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示