我在woocommerce中有一个自定义archive-product
,在该文件中,我显示了与默认woowommerce不同的类别,我将此文件名为archive-product-2
和我的代码:
<?php get_header(); ?>
<!-- Category page -->
<main>
<div class="container-fluid">
<div class="row">
<div class="col-xl-3 col-lg-3 col-md-4 col-sm-12">
<?php get_sidebar(); ?>
</div>
<!-- Category Template -->
<div class="col-xl-9 col-lg-9 col-md-8 col-sm-12">
<div class="productCategoryPage">
<h2 class="productCategoryPageTitle mb-4">دسته:
<?php single_cat_title( '', true ); ?>
</h2>
<ul class="archiveProduct pr-0">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$searchProductsByCategory = [
'posts_per_page' => 5,
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'orderby' => 'id',
'paged' => $paged,
'tax_query' => [
[
'taxonomy' => 'product_category',
'terms' => get_queried_object_id()
]
]
];
$foundProducts = new WP_Query($searchProductsByCategory); if ( have_posts() ) :
while ( have_posts() ) : the_post(); ?>
<li>
<div class="row">
<div class="col-xl-3 col-lg-3 col-md-12 col-sm-12 text-center">
<?php if ( has_post_thumbnail() ) {the_post_thumbnail('first-thumb');} else { ?>
<img class="img-fluid attachment-first-thumb size-first-thumb wp-post-image" src="<?php bloginfo('template_directory'); ?>/assets/img/no-image.png" />
<?php } ?>
</div>
<div class="col-xl-9 col-lg-9 col-md-12 col-sm-12">
<div class="productCategorytitle">
<strong class="en_title"><?php the_title(); ?></strong>
<h2><?php the_field('persiantitle'); ?></h2>
<strong class="archiveRating"><?php the_field('emtiyazfilm'); ?></strong>
</div>
<div class="row">
<div class="col-xl-6 col-lg-9 col-md-12 col-sm-12">
<ul class="filminfoArchive">
<li><b>بازیگران:</b><?php the_field('acter'); ?></li>
<li><b>کارگردان:</b><?php the_field('filmdirector'); ?></li>
<li><b>ژانر:</b><?php global $product; echo $product->get_categories( ' | ', ' ' . _n( ' ', ' ', $cat_count, 'woocommerce' ) . ' ', ' ' ); ?></li>
<li><b>سال تولید:</b><?php the_field('years'); ?></li>
<li><b>کیفیت:</b><?php the_field('quality'); ?></li>
<li><b>زبان:</b><?php the_field('language'); ?></li>
<li><b>زیرنویس:</b><?php the_field('subtitle'); ?></li>
</ul>
</div>
<div class="col-xl-6 col-lg-9 col-md-12 col-sm-12">
<div class="archivePrice"><?php echo $product->get_price_html();?></div>
<div class="addFavorate"><?php echo do_shortcode('[yith_wcwl_add_to_wishlist]'); ?></div>
<?php global $product;
echo apply_filters( 'woocommerce_loop_add_to_cart_link',
sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="btnaddtocardMain %s product_type_%s">%s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( $product->id ),
esc_attr( $product->get_sku() ),
$product->is_purchasable() ? 'add_to_cart_button' : '',
esc_attr( $product->product_type ),
esc_html( $product->add_to_cart_text() )
),
$product ); ?>
<a class="continueArcive" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">ادامه
مطلب</a>
</div>
</div><!-- end row -->
</div>
</div><!-- End Row -->
</li>
<?php endwhile; endif; ?>
<?php wp_pagenavi( array( 'query' => $foundProducts )); ?>
<?php wp_reset_query(); ?>
</ul>
</div><!-- End Template -->
</div><!-- End Row -->
</div><!-- End Container -->
</main>
<?php get_footer(); ?>
这是taxonomy-product_cat.php
代码:(我只将wc_get_template( 'archive-product.php' );
更改为wc_get_template( 'archive-product-2.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-2.php' );
现在我在archive-product-2
中有一个分页,您可以在我的代码中看到,
现在我有2个问题:
我很困惑如何解决这个问题?