【问题标题】:How show media gallery | carbon fields wordpress如何显示媒体库 |碳领域 wordpress
【发布时间】:2021-03-09 18:28:27
【问题描述】:

我在 Wordpress 中使用碳字段。我有问题,因为我无法显示媒体库。我在functions.php中的代码

function crb_attach_post_meta_aboutus() {
    Container::make( 'post_meta', __( 'Singlebramy', 'single' ) )
        ->where( 'post_type', '=', 'dla-domu' )

        ->add_fields( array(
            Field::make( 'media_gallery', 'crb_media_gallery', 'Galeria' )
            ->set_type(  'image'  )
        ));
}

我尝试使用 foreach 但不起作用。请帮帮我。

【问题讨论】:

    标签: php wordpress image-gallery carbon-fields


    【解决方案1】:

    好的,我找到了问题的答案。我使用了foreach和wp_get_attachment_url(),下面我添加了一个代码sn-p来解决这个难题。

    foreach( $media_gallery as $i => $image ){
          if($i == 0){
                $next = 'active';
          }else{
             $next = '';
          }
          echo '<div class="carousel-item '.$next.'">';
          echo '<img src="'.wp_get_attachment_url( $image ).'" class="d-block w-100">';
          echo '</div>';
    }
    

    这是一个带有引导轮播的 sn-p 代码:)

    【讨论】:

      【解决方案2】:

      在 Carbon 字段中显示媒体库:

      $gallery  = carbon_get_post_meta( get_the_ID(), 'crb_media_gallery' );
      
      foreach( $gallery  as $i => $image ){
      
        echo '<img src="'.wp_get_attach`enter code here`ment_url( $image ).'" class="d-block w-100">';
       
      }
      

      【讨论】:

      • 请编辑您的答案以解释您的代码的作用。
      猜你喜欢
      • 2015-05-07
      • 1970-01-01
      • 2011-09-08
      • 1970-01-01
      • 2017-03-05
      • 1970-01-01
      • 1970-01-01
      • 2015-02-20
      • 2015-07-01
      相关资源
      最近更新 更多