woocommerce的taxonomy-product_cat分类模板也需要定义否则可能排版乱了

  • 2020 年 2 月 25 日
  • 筆記

  我们知道woocommerce(下称wc)的archive-product.php模板是定义shop page的,可能比较比较早版本的wc也是用这个文件来定义分类的,但是如果你升级到最新版本的wc会有一个单独的taxonomy-product_cat.php来定义产品分类模板,虽然是通过代码调用archive-product.php,

<?php  /**   * The Template for displaying products in a product category. Simply includes the archive template   *   * This template can be overridden by copying it to yourtheme/woocommerce/taxonomy-product_cat.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  }    wc_get_template( 'archive-product.php' );

  但一定要重新定义这个文件,特别是使用了独立pc和mobile模板,你可以复制一份archive-product.php然后重命名成taxonomy-product_cat.php,这样打开手机端的产品分类就不会出现页面错乱了。这是ytkah困扰了两天才得到的教训,希望有遇到相同问题的朋友借鉴。