2016-08-18 47 views
0

嘿家伙我是新来的wordpress开发和我的问题是我的文件返回的路径,我上传到wordpress文章使用高级自定义字段似乎是输出数组内路径。我的代码如下,请帮助,如果可以的话。我在我之前得到了一个更好的选择,所以我会经常登记。wordpress the_field()包括数组的路径

这是我收到的文件路径:217,DES-书桌图标,图像/ PNG,http://localhost:8888/Wordpress%20development/wp-content/uploads/2016/08/des-desk-icon.png,279,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;?> 
+0

在你的字段配置中,你选择了什么“返回值”?如果您只是将它用作图片源,请尝试使用“图片网址” – Hobo

回答

0

有代码的一个尝试,它将工作。

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;?>