【问题标题】:ACF Repeater w/ Flexible Content Inside内部有灵活内容的 ACF 中继器
【发布时间】:2017-01-07 09:58:34
【问题描述】:

我正在使用高级自定义字段。我有一张直接与他们联系的票,但需要一段时间。我需要立即解决这个问题。

尝试为英雄滑块重复灵活的内容,用户可以在其中添加视频嵌入或图像。如何正确地回显循环中的每一部分?没有出现在 Wordpress 中输入的内容。容器在回响,只是没有内容。

<?php
if (have_rows('add_resorts_hero_image_slide', 'option')) {
    while (have_rows('add_resorts_hero_image_slide', 'option')) {
        the_row();

        $herovideo = the_sub_field('add_resorts_hero_slider_video');
        $heroimage = the_sub_field('add_resorts_hero_slider_image');
            $heroimgsize = 'hero-image';
            $heroimg_array = wp_get_attachment_image_src($heroimage, $heroimgsize);
            $heroimg_url = $heroimg_array[0];


        if (have_rows('choose_resorts_hero_slider_content')) {
            while (have_rows('choose_resorts_hero_slider_content')) {
            the_row();

                echo '<li class="orbit-slide">';

                if( get_row_layout() == 'resorts_slider_video' )

                    echo $herovideo;

                elseif( get_row_layout() == 'resorts_slider_video')
                    echo '<img src="'.$heroimg_url.'" />';

                echo '</li>';

            }
        } 
 }

}

【问题讨论】:

  • 上述代码中的所有内容当前是否正常工作?就像你添加 echo 'image';并回显“视频”;在 if 和 elseif 里面,这些行得通吗?
  • 是的,它很实用。我的问题是如何回显带有变量的 HTML。比如说……
  • 如何在 src="" HTML 中回显 image 变量?
  • iframe 视频和图像的字段类型是什么?它只是一个 URL 和一个图像字段吗?
  • 抱歉耽搁了。视频是oembed的,图片是图片ID。

标签: slider repeater advanced-custom-fields


【解决方案1】:

只是重新发布您的代码的相关部分:

if( get_row_layout() == 'resorts_slider_video' ){
    //Display iFrame Video (this assumes that your field is a URL field.)
    echo '<iframe src="'.get_sub_field('IFRAME URL FIELD NAME GOES HERE').'"></iframe>';
}elseif( get_row_layout() == 'resorts_slider_video'){
    //Display Image (this assumes that your field is an image field, being saved as an Image Object, and you want to output a custom image size)
    $myImage = get_sub_field('IMAGE FIELD NAME GOES HERE');
    echo '<img src="'.$myImage['sizes']['CUSTOM IMAGE SIZE NAME'].'" alt="'.$myImage['alt'].'" />';
}

【讨论】:

  • 我已将我的代码编辑到我目前使用的位置。由于回显视频或图像字段,在 Wordpress 中输入的内容没有出现。
  • 将“the_sub_field”调用更改为“get_sub_field”。 the_sub_field 回显数据,您不希望它这样做。
  • 感谢您的回复!改了,还是一样。我已经仔细检查了字段名称。嗯...
【解决方案2】:

终于弄清楚了我需要什么。希望这个答案可以帮助其他人!

<!--ORBIT SLIDE-->
<?php
if (have_rows('add_resorts_hero_image_slide', 'option')) {
    while (have_rows('add_resorts_hero_image_slide', 'option')) {
        the_row();

            if (have_rows('choose_resorts_hero_slider_content')) {
                while (have_rows('choose_resorts_hero_slider_content')) {
                    the_row();

                    $herovideo = get_sub_field('add_resorts_hero_slider_video');
                    $heroimage = get_sub_field('add_resorts_hero_slider_image');
                    $heroimgsize = 'hero-image';
                    $heroimg_array = wp_get_attachment_image_src($heroimage, $heroimgsize);
                    $heroimg_url = $heroimg_array[0];

                    if( get_row_layout() == 'resorts_slider_video' ) {

                    echo '<li class="video orbit-slide">';
                    echo '<img class="background" src="http://localhost.com/vail/tier2-hero-placeholder.jpg" />';

                       echo '<div class="container">
                                 <div class="watermark"></div>
                                 <iframe id="heroorbitslider-video"
                                         src="'. $herovideo .'"
                                         width="100%" 
                                         frameborder="0" 
                                         scrolling="no" 
                                         allowFullscreen="true" 
                                         allowFullScreen="true" 
                                         webkitAllowFullScreen="true" 
                                         mozAllowFullScreen="true">
                                 </iframe>
                             </div>';
                  echo '</li>';
                }

                elseif( get_row_layout() == 'resorts_slider_image') {

                    echo '<li class="orbit-slide">';
                        echo '<img class="background "src="'. $heroimg_url .'" />';
                    echo '</li>';
                }


            }

        }

    }

}

?>
<!--END ORBIT SLIDE-->

【讨论】:

    猜你喜欢
    • 2013-12-29
    • 2018-05-31
    • 2020-07-10
    • 2016-04-07
    • 2016-02-01
    • 2016-04-07
    • 2022-10-06
    • 2014-07-16
    • 1970-01-01
    相关资源
    最近更新 更多