Number of products in shop page


#1

Hello
in my site at shop page
http://www.artiescarti.it/theshop/shop/

the products are shown on 3 columns, but are shown 10 products and the last row has 2 empty spaces

can we set an odd number of products to show (9 or 6)

thanks


#2

Hello,

I suggest you to create a child theme and add this line of code to its functions.php as described here:

add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 9;' ), 20 );

Sincerely, Roman.


#3

Here is the line of code (it’s cut in message above):

add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 24;’ ), 20 );


#4

Just replace “return 24” to the number of your choice, 6 or 9.


#5

So you will get, for example:

add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 9;’ ), 20 );


#6

hello
why create a child theme?
is not possible add that line in the main theme?

thanks


#7

It is possible to add it to the main theme, but you will have to re-add it after updating the main theme.


#8

ok
thanks

Where exactely in the functions.php do I have add the line?

I tryed to add it at the hand but I recive an error

thanks again


#9

PHP code always has to be within its tags, <?php some code ?>. Opening tag “<?php” is necessary, closing tag “?>” is not necessary, so it is recommended to avoid closing tag at all in files that contain only PHP code (you still must use both tags to separate PHP from HTML). So, recommended function.php structure in terms of tags is:

<?php
some code

#10

I bag your pardon but I can’t understand
…in the file php at the top I have

<?php
/**
 * TheShop functions and definitions
 *
 * @package TheShop
 */

if ( ! function_exists( 'theshop_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 */
function theshop_setup() {

<strong>...ecc</strong>

and in the end

  • Woocommerce
    */
    require get_template_directory() . ‘/woocommerce/woocommerce.php’;

#11

Okay, just put this code at the end of the file:

add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 9;’ ), 20 );


#12

So I did but I have this error:

Parse error: syntax error, unexpected ‘$cols’’ (T_VARIABLE) in /web/htdocs/www.artiescarti.it/home/theshop/wp-content/themes/theshop/functions.php on line 272

thanks


#13

Please check the code carefully, it has to be ‘$cols’, not ‘$cols’’.


#14

…I cheked, in the php file is correct

/**

  • Woocommerce
    */
    require get_template_directory() . ‘/woocommerce/woocommerce.php’;

add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 9;’ ), 20 );


#15

…I’m working on the functions.phf file tha is located in:

www.artiescarti.it/theshop/wp-content/themes/theshop

is it the correct file location?


#16

You can also try WooCommerce Products Per Page plugin.


#17

I GOT IT!!!

the error was in the '
so instead of paste and place I edited the line manually

thanks a lot


#18

I’m glad that you figured it out! :slight_smile:


#19

Hey, I don’t know if this’ll wwork for you but if you are in the dashboard, go to settings-reading-show amount of blogposts --insert number you need that might just fix your product numbers…illogical I know but I think you will have success.


#20

Hello @mj,

Thank you for your suggestion. I, personally, think that this is good idea. We will discuss this issue.

Kind Regards, Roman.