WordPress 4.9.5+WooCommerce 3.3.5:如何将商城页改为显示商品而非分类?
解决WooCommerce商城页默认显示分类而非商品的问题
Hey there, let's fix that shop page issue you're having with WooCommerce 3.3.5 on WordPress 4.9.5. Here are two reliable methods to get your products showing directly instead of categories:
方法1:通过WooCommerce后台设置(优先尝试)
This is the easiest way for most users, no code required:
- Log into your WordPress admin dashboard
- Navigate to WooCommerce > Settings
- Switch to the Products tab, then click the Display sub-tab
- Look for the option labeled "Shop page display"
- Select "Show products" instead of the default "Show product categories"
- Scroll down and click "Save changes"
- Refresh your shop page, and you should see your products directly now!
方法2:用代码强制显示商品(如果主题覆盖了默认设置)
Some themes override WooCommerce's default settings for the shop page. If the first method didn't work, add this code to your theme's functions.php file (or a child theme's functions.php to avoid losing changes when updating your theme):
add_action( 'pre_get_posts', 'custom_force_shop_page_products' ); function custom_force_shop_page_products( $query ) { // Check if we're on the main shop page and it's the main query if ( is_shop() && $query->is_main_query() && ! is_admin() ) { $query->set( 'post_type', 'product' ); $query->set( 'tax_query', null ); // Clear any category filter $query->set( 'product_cat', '' ); // Ensure no category is being queried } }
注意事项:
- Always back up your
functions.phpfile before making changes—one typo can break your site! - Using a child theme is highly recommended, as parent theme updates will overwrite any code added directly to the parent's
functions.php.
内容的提问来源于stack exchange,提问作者Badin
相关产品推荐
相关产品推荐

