【问题标题】:i want to display images of my custom plugin in carousel style我想以轮播风格显示我的自定义插件的图像
【发布时间】:2019-11-05 06:36:48
【问题描述】:

我制作了我的第一个自定义插件,它通过简码显示图片库。当前图像是随机显示的。我想通过使用猫头鹰旋转木马以旋转木马的方式展示它们。

我尝试在我的自定义插件文件夹中包含 owl carousel 的 css 和 js 文件。可能是我的脚本和样式没有被调用。我需要帮助如何在我的自定义代码中添加循环代码。请逐步指导我,因为我是自定义插件开发的初学者。

这是从其中获取图库并包含脚本和样式的元数据,请查看它是否正确。

function gallery_metabox_enqueue($hook) {
    if ( 'post.php' == $hook || 'post-new.php' == $hook ) {
      wp_enqueue_script('gallery-metabox', plugin_dir_url( __FILE__ ) . '/js/gallery-metabox.js', array('jquery', 'jquery-ui-sortable'));

     wp_enqueue_script('gallery-metabox', plugin_dir_url( __FILE__ ) . '/js/owl.carousel.min.js', array('jquery', 'jquery-ui-sortable'));
     wp_enqueue_script('gallery-metabox', plugin_dir_url( __FILE__ ) .'/css/owl.css', array(), null, 'all' );
     /*wp_enqueue_style( 'owl-carousel' );*/
     wp_enqueue_style( 'owl.css', get_stylesheet_uri() );

    }
  }

  add_action('admin_enqueue_scripts', 'gallery_metabox_enqueue');

-----------------------------------------------------------------------------
this is shortcode from where gallery will be displayed in page where shortcode is pasted.

add_shortcode( 'banners', 'display_banners' ); 
function display_banners($atts){
$meta = get_post_meta($atts['id'],'vdw_gallery_id', true);
?>
<div id="owl-demo" class="owl-carousels">
<?php
foreach ($meta as $key => $value) {
$attpost= get_post($value); // declare post variable 
echo '<img class="items" src="'.$attpost->guid.'" />'; 
}
?>
</div>
<?php
   extract(shortcode_atts(array('key' => 'vdw_gallery_id'), $atts));

    if($key && array_key_exists($key, $meta)) {

        return $meta[$key][0];
   }
    exit;
 }
 ?>

【问题讨论】:

    标签: wordpress jquery-plugins customization owl-carousel


    【解决方案1】:
    You can replace with
    
    from : wp_enqueue_script('gallery-metabox', plugin_dir_url( __FILE__ ) .'/css/owl.css', array(), null, 'all' );
         /*wp_enqueue_style( 'owl-carousel' );*/
    
    To : wp_enqueue_style('gallery-metabox', plugin_dir_url( __FILE__ ) .'/css/owl.css', array(), null, 'all' );
         /*wp_enqueue_style( 'owl-carousel' );*/
    

    并确保您能够在源代码中获取 css 和 js (ctrl+u)

    【讨论】:

      【解决方案2】:

      您可以使用以下代码获取图像对象

      $images = get_post_meta($post->ID, 'vdw_gallery_id', true);
      foreach ($images as $image) {
          $image_obj = get_post($image);
          echo $image_obj->post_excerpt;
      }
      

      【讨论】:

      • 感谢您的回复,但我认为您不理解问题。我正在前端获取图片库,但我想使用 owl carousel 在轮播中显示。
      猜你喜欢
      • 2018-05-12
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      • 2019-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多