简体   繁体   English

wordpress the_field()路径,包括数组

[英]wordpress the_field() path including array

Hey guys I'm new to wordpress development and the issue Im having is that the path returned for my files which I uploaded into a wordpress post using advanced custom fields seem to be outputting an array within the path. 嗨,我是wordpress开发的新手,我所遇到的问题是,我使用高级自定义字段上传到wordpress帖子中的文件返回的路径似乎是在该路径中输出数组。 My code is below, please help if you can. 我的代码在下面,如果可以的话请帮忙。 I got an all nighter ahead of me so I'll be checkin in frequently. 我前面整夜未眠,所以我会经常入住。

this is the filepath I'm getting: 217, , des-desk-icon, , , image/png, http://localhost:8888/Wordpress%20development/wp-content/uploads/2016/08/des-desk-icon.png , 279, 279, Array 这是我得到的文件路径: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;?>

Have a try of the code and it will work it . 尝试一下代码,它将起作用。

ACF will return the image as array format and you have to use get_field() and print it using an array format. 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