woocommerce中每页的产品数量

亲爱的编码人员和社区,

我已经对这个问题进行了相当长时间的研究, 尽管我有一定的编码背景, 但似乎无法弄清楚这个问题。到该主题的链接没有帮助, 因为它们都只提示我已经在使用的代码段。

我的Word Press安装正常工作:版本4.8.2和WooCommerce:版本3.3.5

我的主题基本上由2个文件组成, 因为我必须对整个文件进行分解才能找到问题。

functions.php

<?php

add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
    function loop_columns() {
        return 5; // 3 products per row
    }
}

add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 999999999999 ); 

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.
  //
  var_dump($cols);
  $cols = 3;
  return $cols;
}

?>

该代码仅用于将产品类别页面上显示的产品数量限制为3。

和index.php

<?php
get_header();
?>

<div class="container content pr-0 pl-0" >
  <div class="index">
  <?php  if ( have_posts() ) : the_post(); ?>
          <?php the_content(); ?>
  <?php endif; ?>
  </div>
</div>
<?php
get_footer();
?>

这只是任何wordpress安装所需的基本索引文件。

现在我已经尝试使用默认的2017主题更改后端设置, 并且效果很好…所以它不可能是后端的东西。

这里可能是什么问题?

任何帮助或线索将不胜感激!谢谢!


#1


loop_shop_columns过滤器不会影响显示的帖子数, 而只会影响页面上的列数(在开始新行之前经过的产品数)。

实际上, 任何页面上显示的产品数量均来自WordPress设置>阅读”最多显示博客页面”设置。

你还可以使用pre_get_posts过滤器以编程方式更改此数字。


#2


add_action( 'pre_get_posts', 'rc_modify_query_exclude_category' );
// Create a function to excplude some categories from the main query
function rc_modify_query_exclude_category( $query ) {
    // Check if on frontend and main query is modified
    if ( ! is_admin()  ) {
        $query->set( 'posts_per_page', '-1' );
    } // end if
}

来源:

https://www.srcmini02.com/64755.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37389.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?