0
私は店のすべての製品にwhile
でループしようとしています。これは、 "関連製品"機能を変更することです。しかし、それはわずか6回実行されますが、私は49の製品を持っています。すべての製品のワードプレスループ
私は理由を理解できますか?
おかげ
if (is_singular('product')) {
global $post;
// get categories
$terms = wp_get_post_terms($post->ID, 'product_cat');
$title = get_the_title($post);
$pattern = '/[^a-zA-Z0-9 ]/';
// $pattern = '/ /';
$matches = array();
$dummy = preg_match($pattern, $title, $matches);
$posi = strpos($title, $matches[0]);
// print_r($posi);
$productname = substr($title, 0, $posi-1);
// print_r($productname);
$productcolor = substr($title, $posi+3);
// print_r($productcolor);
foreach ($terms as $term) $cats_array[] = $term->term_id;
$query_args = array('orderby' => 'title',
'post__not_in' => array($post->ID),
'posts_per_page' => 200,
'no_found_rows' => 10,
'post_status' => 'publish',
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $cats_array
)
)
);
$r = new WP_Query($query_args);
if ($r->have_posts()) { ?>
<div class="related products">
<h2><?php _e('Related Products', 'woocommerce'); ?></h2>
<?php woocommerce_product_loop_start(); ?>
<?php
$counter = 0;
while ($r->have_posts()) :
$r->the_post();
global $product;
$counter = $counter + 1;
wc_get_template_part('content', 'product');
endwhile; // end of the loop.
print_r($counter)
?>
<?php woocommerce_product_loop_end(); ?>
</div>
<?php
wp_reset_query();
}
}
私は実際にrelated.phpファイルを変換するのに苦労しました。私は戦略を変更し、functions.phpに直接コードを書きました。ご協力いただきありがとうございます ! – Louis