我需要将其更改为仅显示类别id中的产品


I need to change this to display only products from a category id

基本上我只需要这个代码来显示类别id的产品。

它来自一个woocomerrce模板。

任何帮助都将不胜感激!

 <div class="book_wrapper" <?php echo (!empty($book_wrapper)) ? 'style="background-image:url('.esc_url($book_wrapper).');"' : ''; ?>>
                <a id="next_page_button"></a>
                <a id="prev_page_button"></a>
                <div id="loading" class="loading"><?php _e('Loading pages!', THEME_NAME); ?>...</div>
                <div id="mybook" style="display:none;">
                    <div class="b-load">
                        <?php
                           $args = array( 'post_type' => 'product', 'posts_per_page' => -1 );
                           $loop = new WP_Query( $args );
                           $counter = 0;
                           echo "<div><ul>";
                           if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
                           <?php if ($counter == 8): ?>
                           	<?php echo '</ul></div><div><ul>'; $counter = 0; ?>
                           <?php endif ?>
                                <li>
	                                <a href="<?php the_permalink(); ?>">
	                                    <div class="meal-name"><?php the_title(); ?></div>
	                                    <div class="meal-price"><?php echo $product->get_price_html(); ?></div>
	                                </a>
                                </li>
                        <?php $counter++; endwhile; endif; ?>
                        <?php echo '</ul></div>'; ?>
                    </div>
                </div>
            </div>

查看此url以获取更多信息https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters您需要在具有特定类别的WP_Query的参数中添加cat。

 <div class="book_wrapper" <?php echo (!empty($book_wrapper)) ? 'style="background-image:url('.esc_url($book_wrapper).');"' : ''; ?>>
                <a id="next_page_button"></a>
                <a id="prev_page_button"></a>
                <div id="loading" class="loading"><?php _e('Loading pages!', THEME_NAME); ?>...</div>
                <div id="mybook" style="display:none;">
                    <div class="b-load">
                        <?php
                           $args = array( 'post_type' => 'product', 'posts_per_page' => -1, cat=> 'Replace with cat id here' );
                           $loop = new WP_Query( $args );
                           $counter = 0;
                           echo "<div><ul>";
                           if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
                           <?php if ($counter == 8): ?>
                           	<?php echo '</ul></div><div><ul>'; $counter = 0; ?>
                           <?php endif ?>
                                <li>
	                                <a href="<?php the_permalink(); ?>">
	                                    <div class="meal-name"><?php the_title(); ?></div>
	                                    <div class="meal-price"><?php echo $product->get_price_html(); ?></div>
	                                </a>
                                </li>
                        <?php $counter++; endwhile; endif; ?>
                        <?php echo '</ul></div>'; ?>
                    </div>
                </div>
            </div>