Support » Fixing WordPress » Show maximium post / products

  • Resolved nesoor

    (@nesoor)



    Hello WordPress Members,

    I am creating a WordPress template from a scratch.
    The blog shows maximum 4 posts and Woocomemrce shows also maximum 4 products.
    These settings are configurable in Settings > Reading > Blog pages show at most: 4

    The problem is when I set this to 10 because I want woocommerce to show 10 products it also shows 10 posts. How can I configure that Woocommerce only shows 10 products and the blog only 4 posts?

    • This topic was modified 1 year, 4 months ago by  nesoor.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Example:

    <?php $the_query = new WP_Query( 'posts_per_page=3' ); ?>

    https://codex.wordpress.org/Pagination

    https://codex.wordpress.org/Class_Reference/WP_Query

    Also, since you are using WooCommerce, the best place to ask is with them (but they do not support custom themes) – review the docs

    https://docs.woocommerce.com/document/change-number-of-products-displayed-per-page/

    Hello,
    You can use separate query to show post for both blog and WooCommerce.
    Below query is for WooCommerce product query. You can use it anywhere in you sie.
    If will show title only. If you want to add another meta data, then you have to add it with your own markup.
    You WordPress reading setting to the blog post.

    <?php
    $woo_args = array(
            'posts_per_page' => 5,
            'post_type' => 'product'
    );
    $wc_query = new WP_Query($woo_args); 
    if ($wc_query->have_posts()) : 
    while ($wc_query->have_posts()) : 
                    $wc_query->the_post(); 
    ?>
    <h1><?php the_title(); ?></h1>
      
    <?php endwhile; ?>
    <?php wp_reset_postdata(); ?>
    <?php else:  ?>
    <p>
         <?php _e( 'No Products' ); ?>
    </p>
    <?php endif; ?>

    If above code doesn’t work please let know.
    I will try get you ASAP.

    Please refer to my links.

    Hey !

    Thanks for all the replies !
    It finally works now but there is still one small problem 🙂

    I inserted the following code in the home.php

    
    <?php 
    query_posts('posts_per_page=3');
    while(have_posts()) : the_post(); 
    ?>
    

    I put the settings > reading > Blog pages show at most: 10

    The blog shows 3 posts and Woocommerce 10 products but the buttons on the Blog disappeared because they think there are 10 posts on the page while there are just 3 shown out of 10.

    • This reply was modified 1 year, 4 months ago by  nesoor.

    To show – in the WooCommerce Shop Page, a specific number of products, add below to theme functions.php file. Note: Edits to parent theme’s are lost on parent theme update, so use a child theme (or a custom theme).

    In example below the Shop Page would show 9 products.

    
    add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
    
    function new_loop_shop_per_page( $cols ) {
      // $cols contains the current number of products per page based on the value stored on Options -> Reading
      // Return the number of products you wanna show per page.
      $cols = 9;
      return $cols;
    }
    

    (I’m not guessing or copy and pasting from Google, I have and do this type of work.)

    Make sure to remove:

    
    query_posts('posts_per_page=3');
    

    And then just use the settings>reading to set # of posts per page for archive pages. The WooCommerce Shop Page is not an archive page.

    Please let me know if this helps 🙂

    Cool ! Everything works perfectly now.
    My theme is getting step by step better and better 🙂

    Thanks for all the help. I really appreciate it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Show maximium post / products’ is closed to new replies.