如何通过视觉作曲家在前端WordPress页面上显示图像?

时间:2017-08-19 06:11:23

标签: php wordpress custom-wordpress-pages visual-composer

function italy_menu( $menu1, $menu2 ){
    ob_start();

    $menuatts = shortcode_atts(array(
        'menu_image'    =>  '',
        'menu_title'    =>  '',
        'menu_money'    =>  '',
    ), $menu1 );

?>
    <div class="post">
        <a href="#"><img src="<?php echo $menuatts['menu_image']; ?>"/></a>
        <div class="wrapper">
          <h5><a href="#"><?php echo $menuatts['menu_title']; ?></a></h5>
          <span><?php echo $menuatts['menu_money']; ?></span>
        </div>
    </div>
<?php
    return ob_get_clean();
}
add_shortcode('menu','italy_menu');


if(function_exists(vc_map)){
    vc_map(array(
        'name'  =>  'Italy Food Menu',
        'base'  =>  'menu',
        'params'    =>  array(
            array(
                'param_name'        =>  'menu_image',
                'type'              =>  'attach_images',// How to show image on front page.
                'heading'           =>  'Menu Image'
            ),
            array(
                'param_name'        =>  'menu_title',
                'type'              =>  'textfield',
                'heading'           =>  'Menu Title'
            ),
            array(
                'param_name'        =>  'menu_money',
                'type'              =>  'textfield',
                'heading'           =>  'Menu Money'
            ),
        )
    ));
}

如何通过视觉作曲家在前端WordPress页面上显示图像?我想通过视觉作曲家在我的前端展示图像。我正在使用&gt; 'type' => 'attach_images',但它没有显示图像......这是我的代码。

1 个答案:

答案 0 :(得分:0)

$ gallery = shortcode_atts(                     阵列(                         'post_gallery'=&gt; 'post_gallery',                     ),$ atts);

    $image_ids=explode(',',$gallery['post_gallery']);
    $sigle_img = wp_get_attachment_image_src($image_ids[0], "large");
    $img="<div id='tourGallery'><img class='imgthumb' id='' src='".$sigle_img[0]."' style='width:100%' alt=''></div><div id='galleryThumbs'>";
    for($i=0;$i<=9;$i++)
    {
     if($image_ids[$i]!="")
      {
      $imgs = wp_get_attachment_image_src($image_ids[$i], "large"); 
      $img.="<div><img class='imgthumb' id='' src='".$imgs[0]."' style='width:100%' alt=''></div>";
      }
    }
    $img.="</div></div>";
    return $img;