我在哪里可以使用woocommerce图库创建代码

时间:2017-11-02 14:54:31

标签: php wordpress image woocommerce gallery

Woocommerce在今年早些时候为您的图片库提供了启用灯箱功能的选项。如果您想启用图库功能但他们实际上没有说明在哪里,他们会在文档中添加代码。

https://woocommerce.wordpress.com/2017/02/28/adding-support-for-woocommerce-2-7s-new-gallery-feature-to-your-theme/

这是一个重要的前端变化,可以细分为三个独立的新功能; •图像缩放/放大 • 灯箱 •滑块 要在主题中启用这些功能,您必须使用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' );
}

这使您可以灵活地选择要在主题或商店中包含/排除哪些功能。

我不是开发人员,我没有开发人员(并且因为没有让这个选项成为最终用户可以选择或不需要添加代码的选项而感到羞耻!)

我需要知道放置此代码的位置。我正在使用一个名为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' );
}
?>

“我的功能.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

function 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');

/ ------------------------------------------- ---------------------------------------- / / *请勿在此处添加任何代码,否则天空会落下 / / --------------------------------------------- -------------------------------------- * / ?&GT;`

1 个答案:

答案 0 :(得分:0)

您必须将function.php中的代码放在<?php?>标记之间。

另外注意:您可以将所有这些图库的效果或其中只有少数效果放在您的网站上。例如,如果您的网站性能下降,您可以删除或将//添加到

add_theme_support( 'wc-product-gallery-zoom' );

或其他影响。

相关问题