Php 获取当前产品类别内的产品
我目前正在玩V2.0.13,我试图显示当前产品类别中的每个产品(例如,在构建页面上显示建筑产品),我已设法显示当前类别中的单个产品,但如果该产品也在另一个类别中(例如,建筑和环境)然后,当前类别中断,并显示来自建筑或环境的零产品 如果我能在展示当前类别的产品方面得到一些建议/帮助,并允许它与多个类别的产品一起使用,我真的非常感谢这些帮助和时间 我非常高兴能重新编码这整个部分,让它工作,这是我下面的代码,如果我遗漏了什么,请告诉我 多谢各位Php 获取当前产品类别内的产品,php,wordpress,categories,woocommerce,product,Php,Wordpress,Categories,Woocommerce,Product,我目前正在玩V2.0.13,我试图显示当前产品类别中的每个产品(例如,在构建页面上显示建筑产品),我已设法显示当前类别中的单个产品,但如果该产品也在另一个类别中(例如,建筑和环境)然后,当前类别中断,并显示来自建筑或环境的零产品 如果我能在展示当前类别的产品方面得到一些建议/帮助,并允许它与多个类别的产品一起使用,我真的非常感谢这些帮助和时间 我非常高兴能重新编码这整个部分,让它工作,这是我下面的代码,如果我遗漏了什么,请告诉我 多谢各位 <ul class="products">
<ul class="products">
<?php
global $post, $product;
$categ = $product - > get_categories();
$categ2 = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $categ);
?>
<?php
global $product;
$args = array('post_type' = > 'product', 'posts_per_page' = > '999', 'product_cat' = > $categ2, );
$loop = new WP_Query($args);
while ($loop - > have_posts()): $loop - > the_post();
global $product;
?>
<li>
<a href = "<?php echo get_permalink(); ?>">
<?php
if (has_post_thumbnail()) {
$image = get_the_post_thumbnail($post - > ID, apply_filters('single_product_large_thumbnail_size', 'shop_single'));
$image_title = esc_attr(get_the_title(get_post_thumbnail_id()));
$image_link = get_permalink($product_id);
$attachment_count = count($product - > get_gallery_attachment_ids());
echo apply_filters('woocommerce_single_product_image_html', sprintf('<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" rel="prettyPhoto'.$gallery.'">%s</a>', $image_link, $image_title, $image), $post - > ID);
} else {
echo apply_filters('woocommerce_single_product_image_html', sprintf('<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src()), $post - > ID);
} ?>
</a>
<div>
<h3>
<a href="<?php echo get_permalink(); ?>"><?php the_title();?></a>
<span>
<?php
if ($price_html = $product - > get_price_html()) {
?>
<span class = "price">
<?php echo $price_html; ?>
</span>
<?php } ?>
</span>
</h3>
</div>
<div>
<p>
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt, 15);
?>
</p>
</div>
</li>
<?php endwhile; ?>
</ul>
-
“,$image\u link,$image\u title,$image),$post->ID);
}否则{
echo应用过滤器('woocommerce\u single\u product\u image\u html',sprintf('',woocommerce\u占位符\u img\u src()),$post->ID);
}
?>
<?php if ( have_posts() ) : ?>
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<div class="courses-main">
<ul class="products">
<?php while ( have_posts() ) : the_post(); ?>
<li>
<a href="<?php echo get_permalink(); ?>">
<?php
if ( has_post_thumbnail() ) {
$image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) );
$image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );
$image_link = get_permalink( $product_id );
$attachment_count = count( $product->get_gallery_attachment_ids() );
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_title, $image ), $post->ID );
} else {
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src() ), $post->ID );
}
?>
</a>
<div>
<h3>
<a href="<?php echo get_permalink(); ?>"><?php the_title();?></a>
<span>
<?php if ( $price_html = $product->get_price_html()) { ?>
<span class="price"><?php echo $price_html; ?></span>
<?php } ?>
</span>
</h3>
</div>
<div>
<p>
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,15);
?>
</p>
</div>
</li>
<?php endwhile;?>
</ul>
</div>
<?php woocommerce_product_loop_end(); ?>
<?php endif; ?>