简体   繁体   English

如何添加图像以从adv自定义字段和自定义帖子类型循环播放

[英]How to add image to loop from adv custom fields and custom post type

 <?php 
          // the query
          $loop = new WP_Query( array( 'post_type' => 'features', 'orderby' => 'post_id', 'order' => 'ASC' ) ); ?>

            <?php if ( $loop->have_posts() ) : ?>

              <!-- the loop -->
              <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

               <img src="<?php the_field('image'); ?>">

              <?php endwhile; ?>
              <!-- end of the loop -->   
              <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>            
          <?php else : ?>
              <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
        <?php endif; ?>

I have a problem with adding image to loop. 我在添加图片到循环时遇到问题。 I create an custom image field assigned to custom post type "features" and I want to add this image field to loop. 我创建一个分配给自定义帖子类型“功能”的自定义图像字段,并且我想将此图像字段添加到循环中。 This way is bad becouse in console in src="" is: 这种方式不好,因为在src =“”中的控制台中是:

http://localhost/konkursy/wp-content/uploads/2019/01/smartphone_samsung.png, http://localhost/konkursy/konkursy_internetowe/caruzela-1/smartphone_samsung/ , balbla, 1, sad, asd, smartphone_samsung, inherit, 56, 2019-01-02 10:56:12, 2019-01-02 12:06:21, 0, image/png, image, png, http://localhost/konkursy/wp-includes/images/media/default.png , 200, 150, Array"> http://localhost/konkursy/wp-content/uploads/2019/01/smartphone_samsung.png、http :// localhost / konkursy / konkursy_internetowe / caruzela-1 / smartphone_samsung / ,balbla,1,sad,asd,smartphone_samsung,继承,56,2019-01-02 10:56:12,2019-01-02 12:06:21,0,image / png,image,png, http:// localhost / konkursy / wp-includes / images / media /default.png、200、150 ,数组“>

I don't know how to do this with array becouse this field is assigned to post type not to template page 我不知道如何使用数组执行此操作,因为此字段被分配为帖子类型而不是模板页面

<?php 
$image = get_field('image');
?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />

This way is not working 这种方式不起作用

Maybe someone who wants to help me can help this: https://www.advancedcustomfields.com/resources/image/ 也许想帮助我的人可以帮助您: https : //www.advancedcustomfields.com/resources/image/

Problem solved. 问题解决了。

In adv custom field options you can change array to URL; 在adv自定义字段选项中,您可以将数组更改为URL。

or second option: add array to loop not to WP_Query like (like I so far) 或第二个选择:添加数组以不像WP_Query那样循环(就像我到目前为止)

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

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