【发布时间】:2018-04-15 03:40:41
【问题描述】:
Woocommerce 今年早些时候取消了为您的图片库启用灯箱功能的选项。如果您想启用图库功能,他们会在文档中添加代码,但实际上并没有说明在哪里。
这是一个重大的前端更改,可以分解为三个独立的新功能; • 图像缩放/放大 • 灯箱 • 滑块 要在您的主题中启用这些功能中的每一个,您必须使用 add_theme_support() 声明支持,如下所示:
add_action( 'after_setup_theme', 'yourtheme_setup' );
function yourtheme_setup() {
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
}
这使您可以灵活地准确选择要在您的主题或商店中包含/排除的功能。
我不是开发人员,我没有开发人员(WC 感到羞耻,因为它没有使最终用户无需添加代码就可以选择或不选择此选项!)
我需要知道将这段代码放在哪里。我正在使用一个名为 mystile1 的子主题。我有一个名为“Theme Functions (function.php)”的文件和一个名为“custom.css”的文件,据说它专门用于添加代码来修改我的子主题样式。
我不知道我应该把上面的代码放在哪个文件中以及放在哪里。这些文件中的每一个都没有一个名为“after_setup_theme”的行所以我可以安全地在其中一个文件(哪个?)中添加如下代码,用我的主题名称替换“yourtheme”:
add_action( 'after_setup_theme', 'mystile1_setup' );
function mystile1_setup() {
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
}
或任何其他建议非常感谢。
谢谢。
回应:
以下是我的functions.php 文件中的内容。我是将代码放在新括号之间的顶部还是放在下面的部分中: /---------------------------------------------- --------------------------------------/ /* 您可以在 下方添加自定义函数/ /------------------------------------------ --------------------------------------------------*/
function mystile1_setup() {
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
}
?>
“我的 FUNCTIONS.PHP 文件”包括
<?php
// File Security Check
if ( ! empty( $_SERVER['SCRIPT_FILENAME'] ) && basename( __FILE__ ) == basename( $_SERVER['SCRIPT_FILENAME'] ) ) {
die ( 'You do not have sufficient permissions to access this page!' );
}
?>
<?php
/------------------------------------------ ----------------------------------------------------/ /* 启动 WooThemes 功能 - 请不要编辑此部分 / /------------------------------------------ --------------------------------------------------*/
// Define the theme-specific key to be sent to PressTrends.
define( 'WOO_PRESSTRENDS_THEMEKEY', 'zdmv5lp26tfbp7jcwiw51ix9sj389e712' );
// WooFramework init
require_once ( get_template_directory() . '/functions/admin-init.php' );
/------------------------------------------ ----------------------------------------------------/ /* 加载特定于主题的文件,支持通过子主题覆盖。 /---------------------------------------------- --------------------------------------/
$includes = array(
'includes/theme-options.php', // Options panel settings and custom settings
'includes/theme-functions.php', // Custom theme functions
'includes/theme-actions.php', // Theme actions & user defined hooks
'includes/theme-comments.php', // Custom comments/pingback loop
'includes/theme-js.php', // Load JavaScript via wp_enqueue_script
'includes/sidebar-init.php', // Initialize widgetized areas
'includes/theme-widgets.php', // Theme widgets
'includes/theme-install.php', // Theme installation
'includes/theme-woocommerce.php' // WooCommerce options
);
// Allow child themes/plugins to add widgets to be loaded.
$includes = apply_filters('woo_includes', $includes);
foreach ( $includes as $i ) {
locate_template( $i, true );
}
/------------------------------------------ ----------------------------------------------------/ /* 您可以在 下方添加自定义函数/ /------------------------------------------ --------------------------------------------------*/
// CUSTOM FUNCTION ADDED TO ADDRESS LACK OF ADD-TO-CART BUTTONS ON VARIABLE ITEMS
// AS DOCUMENTED AT: http://wordpress.org/support/topic/plugin-woocommerce-excelling-ecommerce-checkout-button-not-showing-on-woo-commerce-product/page/2?replies=36#post-3263097
函数 mv_my_theme_scripts() { wp_enqueue_script('add-to-cart-variation', get_template_directory_uri() . '/js/add-to-cart-variation.js',array('jquery'),'1.0',true); } add_action('wp_enqueue_scripts','mv_my_theme_scripts');
/------------------------------------------ ----------------------------------------------------/ /* 不要在下面添加任何代码,否则天会塌下来/ /------------------------------------------ --------------------------------------------------*/ ?>`
【问题讨论】:
-
您需要将此代码放在function.php文件中,该文件位于您的主题文件夹中
标签: php wordpress image woocommerce gallery