首页 > 解决方案 > 在 Woocommerce 的不同页面上加载 flexslider

问题描述

我已经使用这个简码在我的主页上加载了一个产品

<?php echo do_shortcode('[product_page id="195"]');?>

它会在产品下方和右侧产品标题、价格、数量和添加到购物车按钮上加载带有主图像和小缩略图的产品。这是我需要的。但是图像没有滑动功能或缩放功能。据我所知,如果您查看特定的产品页面,它会在产品图像上加载 flex 滑块和 jquery 缩放插件,以便它们可以像轮播一样滑动并单击它们来缩放图像。

知道如何使此功能也可以在我的主页上运行吗?

标签: jquerywordpresswoocommerce

解决方案


我设法使用以下代码解决了这个问题。

// Enqueue/Add CSS and JS files
function amd_enqueue(){
  // here home-page.php is the name of the template where it needs to load
  if(is_page_template("home-page.php")){
      wp_enqueue_script('zoom');
      wp_enqueue_script('flexslider');
      wp_enqueue_script('photoswipe-ui-default');
      wp_enqueue_style('photoswipe-default-skin');
      add_action( 'wp_footer', 'woocommerce_photoswipe' );
  }
}

add_action( 'wp_enqueue_scripts', 'amd_enqueue' );

推荐阅读