forked from collins401/Bytecats
/
single-product.php
85 lines (66 loc) · 1.76 KB
/
single-product.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php get_header(); ?>
<div class="grid-3-4 main" role="main">
<!-- section -->
<section>
<?php cmp_breadcrumbs();?>
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- post title -->
<h1>
<?php the_title(); ?>
</h1>
<div class="entry-article">
<?php the_content(); // Dynamic Content ?>
</div>
<?php
// 按同分类获取相关产品
$custom_taxterms = wp_get_object_terms( $post->ID, 'location', array('fields' => 'ids') );
// arguments
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 3, // you may edit this number
'orderby' => 'rand',
'tax_query' => array(
array(
'taxonomy' => 'location',
'field' => 'id',
'terms' => $custom_taxterms
)
),
'post__not_in' => array ($post->ID),
);
$related_items = new WP_Query( $args );
// loop over query
if ($related_items->have_posts()) :
echo '<h3 class="related">相关产品</h3>';
echo '<ul class="row clearfix">';
while ( $related_items->have_posts() ) : $related_items->the_post();
?>
<li class="gird-1-4">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php echo post_thumbnail('110','90'); ?></a>
</li>
<?php
endwhile;
echo '</ul>';
endif;
// Reset Post Data
wp_reset_postdata();
?>
</article>
<!-- /article -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h1><?php _e( 'Sorry, 暂未录入资料.', 'html5blank' ); ?></h1>
</article>
<!-- /article -->
<?php endif; ?>
</section>
<!-- /section -->
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>