简体   繁体   English

Woocommerce查看所有产品链接分页

[英]Woocommerce View all Products Link Pagination

I'm trying to find a way to create view all button in the Woocommerce pagination. 我试图找到一种在Woocommerce分页中创建“查看全部”按钮的方法。 All other sources seem to be outdated and not working. 所有其他来源似乎已经过时,无法正常工作。 Currently found one source that is quite recent, but still not working. 当前找到了一个很新的消息源 ,但仍然无法正常工作。

So right now I have this: 所以现在我有这个:

if( isset( $_GET['showall'] ) ){ 
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return -1;' ) ); 
}
else {
    add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 25;' ) );
}

And added this for the HTML link in the pagination.php: 并将其添加到pagination.php中的HTML链接中:

    echo '<li><a href="';
    echo curPageURL();
    echo '?showall=1">All</a></li>'; 

The html link is showing, but it doesn't seem to run the function view all. html链接正在显示,但似乎并未全部运行该功能视图。

Is there something I may be doing incorrectly? 我可能做错了什么吗? or is this method outdated? 还是这种方法过时了?

Help is greatly appreciated. 非常感谢您的帮助。

The create_function function may still be supported in some situations, but it is highly discouraged. 在某些情况下仍可能支持create_function函数,但强烈建议不要这样做。 It is actually one of a few functions that when enabled opens your website up to a number of hacking vulnerabilities, which is why in later versions of PHP it has been deprecated. 实际上,它是少数几个功能之一,启用该功能后,您的网站可能会受到许多黑客攻击,这就是为什么在更高版本的PHP中不推荐使用的原因。 I'd bet your host has it disabled and thus the code you have is not working possibly because of that. 我敢打赌,您的主机已将其禁用,因此您所拥有的代码可能因此而无法正常工作。

Doing a quick google I found documentation on how to carry out what you said here . 快速浏览Google,我发现了有关如何执行此处所说内容的文档。 Now with a bit of modification based on what you have so far, I'd try this: 现在,根据您到目前为止的内容进行一些修改,我将尝试这样做:

add_filter('loop_shop_per_page', 'my_per_page_filter', 100);

function my_per_page_filter($cols) {
  return isset($_GET['showall']) ? -1 : $cols;
}

In the code above I am using a bit of code magic to say if $_GET['showall'] is set, then return -1 else the regular number of columns in $cols . 在上面的代码中,我使用一些代码魔术来说明是否设置了$_GET['showall'] ,然后返回-1,否则返回$cols的常规列数。 I have also set the priority of the filter to 100 so hopefully it runs after other filters, if you find this code does not work then try a much higher value like 99999. 我还将过滤器的优先级设置为100,因此希望它可以在其他过滤器之后运行,如果您发现此代码不起作用,请尝试更高的值,例如99999。

Hope this helps! 希望这可以帮助!

Koda 幸田

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM