2

我正在尝试使用可视化作曲家 attach_images 创建自定义图像滑块,但无法完全弄清楚如何从图像 ID 数组中获取 URL。任何帮助,将不胜感激。

var_dump($bg_images) 返回字符串 (9) "19,6,1692"

vc_map( array(
     "name" => __( "Fading Background Block", "farrat_vc" ),
     "base" => "block_background",
     "class" => "",
     "category" => __( "Farrat Shortcodes", "farrat_vc"),
     "as_parent" => array('except' => 'farrat_panel'), // Use only|except attributes to limit child shortcodes (separate multiple values with comma)
     "content_element" => true,
     "show_settings_on_create" => true,
     "is_container" => true,
     'admin_enqueue_css' => array(get_template_directory_uri().'/wp-content/themes/unite/inc/css/gallery.css'),
     "params" => array(
            array(
                 "type" => "attach_images",
                 "heading" => __( "Backgroud Images", "farrat_vc" ),
                 "param_name" => "bg_images",
            ),
        ),
  "js_view" => 'VcColumnView'
) );
4

2 回答 2

7

//嗨试试这个,这是完美的工作

//Param Registration

  function designas_partners() {
    // Title
    vc_map(
        array(
            'name' => __( 'Clients' ),
            'base' => 'designas_partners_content',
            'category' => __( 'Easy Component' ),
            'params' => array(


                array(
                "type"        => "attach_images",
                "heading"     => esc_html__( "Add Clients Images", "appcastle-core" ),
                "description" => esc_html__( "Add Clients Images", "appcastle-core" ),
                "param_name"  => "screenshots",
                "value"       => "",
                ),

            )
        )
    );
    }

add_action( 'vc_before_init', 'designas_partners' );

// 短代码

function designas_partners_content_function( $atts, $content ) {
$gallery = shortcode_atts(
    array(
        'screenshots'      =>  'screenshots',
    ), $atts );

 $image_ids = explode(',',$gallery['screenshots']);
 $return = '
    <div class="clients">';
    foreach( $image_ids as $image_id ){
    $images = wp_get_attachment_image_src( $image_id, 'company_logo' );
    $return .='<div class="images"><img src="'.$images[0].'" alt="'.$atts['title'].'"></div>';
    $images++;
    }
    $return .='</div>';
return $return;
}   
add_shortcode( 'designas_partners_content', 'designas_partners_content_function' ) 
于 2017-06-09T03:25:49.390 回答
0

我在循环中找到了一个解决方法,不需要计数器,循环wp_get_attachment_image( $image_id, 'full' );将为您提供您在 wordpress 面板上使用的所有信息。

我要感谢@sushovan bhowmik 正在寻找这个,我认为这将有助于避免大量变量调用图像:)

<?php

function vc_gallery_carrousel($atts, $content) {
  // Attributes
  $gallery = shortcode_atts(
    array(
    'carrousel_images'  =>  'carrousel_images',
  ),
    $atts );
  // Attributes in var
  $image_ids=explode(',',$gallery['carrousel_images']);


  // Output Code
  $output .= '<section class="loopclientsimg">';
  $output .= '<article>';
  $output .= '<div>';
  $output .= '<ul>';

  foreach( $image_ids as $image_id ){
    $output .='<li>';
    $output .= wp_get_attachment_image( $image_id, 'full' );
    $output .='</li>';
  }

  $output .= '</ul>';
  $output .= '</div>';
  $output .= '</article>';
  $output .= '</section>';

  return $output;
}

add_shortcode( 'vc_img_carrousel', 'vc_gallery_carrousel' );
于 2019-01-31T16:37:07.463 回答