繁体   English   中英

wordpress the_field()路径,包括数组

[英]wordpress the_field() path including array

嗨,我是wordpress开发的新手,我所遇到的问题是,我使用高级自定义字段上传到wordpress帖子中的文件返回的路径似乎是在该路径中输出数组。 我的代码在下面,如果可以的话请帮忙。 我前面整夜未眠,所以我会经常入住。

这是我得到的文件路径:217,,des-desk-icon ,,, image / png, http:// localhost:8888 / Wordpress%20development / wp-content / uploads / 2016/08 / des-desk- icon.png279,279 ,数组

<?php while ( have_posts() ) : the_post(); ?>
                <h1><?php the_field('title'); ?></h1>
                <p><?php the_field('description'); ?></p>

                <?php if(get_field('column_description')): ?>
                    <div class="column_1">
                        <div class="column_1_image">
                        <img src="<?php the_field('column_1_image'); ?>"/>  
                        </div>
                        <div class="column_1_description">
                        <p><?php the_field('column_description'); ?></p>
                        </div>
                    </div>
                <?php endif; ?>
                <?php if(get_field('column_2_description')): ?>
                    <div class="column_2">
                        <div class="column_2_image">
                            <img src="<?php the_field('column_2_image'); ?>"/>
                        </div>
                        <div class="column_2_description">
                            <p><?php the_field('column_2_description'); ?></p>
                        </div>
                    </div>
                <?php endif; ?>
            <?php endwhile;?>

尝试一下代码,它将起作用。

ACF将以数组格式返回图像,您必须使用get_field()并以数组格式打印它。

<?php while ( have_posts() ) : the_post(); ?>
    <h1><?php the_field('title'); ?></h1>
    <p><?php the_field('description'); ?></p>

    <?php if(get_field('column_description')): ?>
        <div class="column_1">
            <div class="column_1_image">
            <?php
                $col1_image =get_field('column_1_image');
            ?>    
            <img src="<?php echo $col1_image['url']; ?>"/>  
            </div>
            <div class="column_1_description">
            <p><?php the_field('column_description'); ?></p>
            </div>
        </div>
    <?php endif; ?>
    <?php if(get_field('column_2_description')): ?>
        <div class="column_2">
            <div class="column_2_image">
                <?php
                $col2_image =get_field('column_2_image');
                ?> 
                <img src="<?php echo $col2_image['url']; ?>"/>
            </div>
            <div class="column_2_description">
                <p><?php the_field('column_2_description'); ?></p>
            </div>
        </div>
        <?php endif; ?>
<?php endwhile;?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM