有时,当我打开一个产品页面时,错误的产品图片会弹出在轮播的主图片和第一个图片中。这不是每次,而是随机的。同样,错误的图像并非每次都一样。
这是链接: http://www.asdbmx.nl/wp-content/uploads/2019/10/troy-lee-designs-d2-delta-silver-blue-0.jpg
好人是这样的: Good version
错误的代码如下:Wrong version
有人知道导致问题的原因以及如何解决吗? 真令人沮丧的是,有时候它会工作,有时却不会
我正在使用最新版本的woocommerce,我使用的主题是Avada(也是最新版本)。
我希望有人能帮助我。
谢谢。
这是single-product.php的代码 希望你能帮帮我
代码:
<?php
/**
* The Template for displaying all single products
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
get_header( 'shop' ); ?>
<?php
/**
* woocommerce_before_main_content hook.
*
* @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* @hooked woocommerce_breadcrumb - 20
*/
do_action( 'woocommerce_before_main_content' );
?>
<?php while ( have_posts() ) : ?>
<?php the_post(); ?>
<?php wc_get_template_part( 'content', 'single-product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php
/**
* woocommerce_after_main_content hook.
*
* @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action( 'woocommerce_after_main_content' );
?>
<?php
/**
* woocommerce_sidebar hook.
*
* @hooked woocommerce_get_sidebar - 10
*/
do_action( 'woocommerce_sidebar' );
?>
<?php
get_footer( 'shop' );
/* Omit closing PHP tag at the end of PHP files to avoid "headers already sent" issues. */
答案 0 :(得分:1)
我看过您的网站,看不到后端,这纯粹是假设性的……疯狂的猜测:
对我来说,好像2个循环彼此弄乱了。我想说的是,在您的产品页面上(也许是?),您没有在完成循环后重设发布数据wp_reset_postdata()
或未正确重设查询wp_reset_query()
。但是没有任何代码,这只是一个疯狂的猜测。
这可能只是一个愚蠢的错误,可以很快解决。
如果需要任何帮助,应该考虑发布页面源代码(如果使用woocomerce,则问题可能出在产品页面上)。
https://developer.wordpress.org/reference/functions/wp_reset_postdata/ https://developer.wordpress.org/reference/functions/wp_reset_query/
答案 1 :(得分:1)
再次感谢您的帮助!
我将尝试使用新的“调试头盔” 我知道主题的一部分..但是那时候我没有...
如今,我使用Divi。它更快,不需要额外的插件。 并且更容易添加CSS和javascript。
再次感谢您的帮助!