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

我在添加圖片到循環時遇到問題。 我創建一個分配給自定義帖子類型“功能”的自定義圖像字段,並且我想將此圖像字段添加到循環中。 這種方式不好,因為在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,繼承,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 ,數組“>

我不知道如何使用數組執行此操作,因為此字段被分配為帖子類型而不是模板頁面

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

這種方式不起作用

也許想幫助我的人可以幫助您: https : //www.advancedcustomfields.com/resources/image/

問題解決了。

在adv自定義字段選項中,您可以將數組更改為URL。

或第二個選擇:添加數組以不像WP_Query那樣循環(就像我到目前為止)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM