微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

cmb2 字段类型:文件未在前端显示图像?

如何解决cmb2 字段类型:文件未在前端显示图像?

添加了所有代码,后端还可以,但在前端 img 源未连接并且在前端不显示图像。

代码文件

add_shortcode('client-section','home_client_section_shortcode');

function home_client_section_shortcode($attr,$content){

     $client =  extract(shortcode_atts( array(
        'title'     => 'Oue Clients','subtitle'  => 'Some of the best.'

      ),$attr) );

  ob_start(); ?>

    <section>
      <div class="container">
        <div class="title center">
          <h4 class="upper"><?PHP echo $subtitle; ?></h4>
          <h3><?PHP echo $title; ?><span class="red-dot"></span></h3>
          <hr>
        </div>
        <div class="section-content">
          <div class="Boxes clients">

            <?PHP 

             $client = new WP_Query( array(
                'post_type'       => 'agro-client','posts_per_page'  => 10

              ));

              $logo =  get_post_meta( get_the_id(),'_client-logo',true);

              while($client->have_posts()): $client->the_post(); 

               
              ?>
              

                 <div class="col-sm-4 col-xs-6 border-right border-bottom">

                  <img src="<?PHP echo wp_get_attachment_image($logo,'large'); ?>" alt="" data-animated="true" class="client-image">

                 </div>

              
            <?PHP endwhile; ?>

          </div>
        </div>
      </div>
    </section>

  <?PHP return ob_get_clean();
}

Cmb2 字段

// Home Client Section Meta Box

    $client= new_cmb2_Box( array(
        'title'  => ' Client logo Upload Fields','id'     => 'client_fields','object_types'  => array('agro-client')

    ));

    $client-> add_field( array(
        'name'  => 'Upload Client logo','id'    => '_client-logo','type'  => 'file','options' => array(
        'url' => false,// Hide the text input for the url
        ),'text'    => array(
        'add_upload_file_text' => 'Add or Upload logo' // Change upload button text. Default: "Add or Upload File"
        ),));

}

函数文件

// Custom post type Client 

    register_post_type('agro-client',array(
        'labels'    => array(
            'name'          => 'Client','add_new'       => 'Add New Client','add_new_item'  => 'Add New Client'
        ),'public'    => true,'supports'  => array('comments')

    ));

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。