dseslyh6662605 2016-05-06 21:42
浏览 79
已采纳

高级自定义字段获取子字段幻灯片图像

When i use this type of code

<?php echo get_sub_field('slide_image')['url']; ?>

then it's give me a

Parse error: syntax error, unexpected '[', expecting ',' or ';' in /home/sites/xyz.com/public_html/wp-content/themes/abc/partials/banner-images.php on line 9

this sort of error so what can i do in this situation. my total code is below

<?php if(have_rows('banner_slides')): // if have rows ?>

    <div class="slideshow slideshow--banner" data-palm="palm-hidden">

        <span id="prev" class="cycle-prev"><</span>

        <?php while ( have_rows('banner_slides') ) : the_row(); // Loop through slides ?>

            <div class="slideshow__slide" style="background-image: url(<?php echo get_sub_field('slide_image')['url']; ?>);">
  • 写回答

2条回答 默认 最新

  • dosin84644 2016-05-06 21:58
    关注

    It depends on what the return type of your sub-field is(you can set this while editing the sub-field). It will either by an array, an image url, or an image id.

    If it's an array:

    $img = get_sub_field('slide_image');
    <div class="slideshow__slide" style="background-image: url(<?php echo $img['url']; ?>);">
    

    If it's a url:

    $img = get_sub_field('slide_image');
    <div class="slideshow__slide" style="background-image: url(<?php echo $img; ?>);">
    

    If it's an id:

    $img = get_sub_field('slide_image');
    <div class="slideshow__slide" style="background-image: url(<?php echo get_permalink($img); ?>);">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后的密码
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面