因此在主题目录中的单产品目录中使用related.php,以避免覆盖更新我试图找到一种方法在每个相关产品上显示自定义字段。
<div class="related products">
<h2><?php _e( 'You might also like...', 'woocommerce' ); ?></h2>
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
</div>
我猜测并尝试了各种各样的事情以避免在这里使用默认模板。
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
做
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<div>
<?php the_title(); ?>
/// output image
/// out put custom field from each product
</div>
<?php endwhile; // end of the loop. ?>
答案 0 :(得分:0)
if ( $products->have_posts() ) : ?>
<div class="related products">
<h2><?php _e( 'You might also like...', 'woocommerce' ); ?></h2>
<div id="grid-wrapper">
<div id="the-grid">
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php //wc_get_template_part( 'content', 'product' ); ?>
<div class="grid-rect iso isotope-item">
<a href="<?php echo get_permalink(); ?>"> <!-- get product url -->
<?php if ( has_post_thumbnail() ) {the_post_thumbnail();}?> <!-- get product image -->
<h3><?php echo the_title() . " by, " . get_post_meta( get_the_ID(), 'wpcf-bb_author', true ); ?></h3> <!-- get tiel and author from custom field -->
</a>
</div>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
</div> <!-- end of the-grid -->
</div> <!-- end of grid wrapper -->
</div> <!-- end of related -->
<?php endif;