-
Notifications
You must be signed in to change notification settings - Fork 1
/
taxonomy-product-categories.php
56 lines (49 loc) · 1.3 KB
/
taxonomy-product-categories.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
get_header();
?>
<section class="categories">
<div class="container">
<?php
// Get the current term object
$term = get_queried_object();
// Display the category title and description
echo '<h2>' . $term->name . '</h2>';
echo '<p>' . $term->description . '</p>';
?>
<div class="taxonomy-wrapper grid">
<?php
// Query posts in the current category
$args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product-categories',
'field' => 'slug',
'terms' => $term->slug
)
)
);
$products = new WP_Query( $args );
// Display the posts in the category
if ( $products->have_posts() ) :
while ( $products->have_posts() ) :
$products->the_post();
?>
<article class="taxonomy">
<?php the_post_thumbnail(); ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p><?php echo wp_trim_words(get_the_excerpt(), 22); ?></p>
<a href="<?php the_permalink(); ?>" class="taxonomy__link button">Read More</a>
</article>
<?php
endwhile;
endif;
// Reset post data
wp_reset_postdata();
?>
</div>
</div>
</section>
<?php
get_footer();
?>