如何在不使用woocommerce中的taxonomy-product_cat页面的情况下仅显示类别页面上的子类别

时间:2016-02-03 11:28:10

标签: wordpress woocommerce

<?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 	    http://docs.woothemes.com/document/template-structure/
 * @package 	WooCommerce/Templates
 * @version     1.6.4
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}


wc_get_template( 'archive-category.php' );
 

我正在开发一个电子商务网站,因为我想只显示带有图像和名称的子类别,然后在点击子类别名称之后,它应该访问子类别产品页面而不影响taxonomy-product_cat页面该做什么请有人可以帮忙吗? 这是我的代码 - taxonomy-product_cat.php和archive-category.php

<?php
/**
 * The Template for displaying product archives, including the main shop page which is a post type archive
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/archive-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 	    http://docs.woothemes.com/document/template-structure/
 * @author 		WooThemes
 * @package 	WooCommerce/Templates
 * @version     2.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

get_header(); ?>
	
  
  
  
  <div class="container-fluid"><div class="row">
  
  
  
  <div class="col-md-10 col-md-offset-2">
  
 <?php
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
  $category_name = $term->name;
    $category_id = $term->term_id;
	
  $category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
  $image = wp_get_attachment_url($category_thumbnail); ?>
  
 
  
  
  <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
    <div class="hovereffect">
        <?php echo '<img class="img-responsive" src="'.$image.'">'; ?>
        <div class="overlay">
           <h2><?php  echo '<a href="' . get_category_link( $category_id ) . '">' .  $category_name . '</a>';  ?></h2>
           
        </div>
    </div>
</div>
  
  
  
  
  
  

 <?php }


 ?>
 
 </div></div></div>
<?php get_footer(); ?>

0 个答案:

没有答案