admin管理员组文章数量:1431317
the problem I got: I need to force a list view for products which are shown on a specific page only for mobile devices, for me the perfect solution would be an additional url parameter -> '&product_view=list', before it is redirected to the page.
Thank you!
the problem I got: I need to force a list view for products which are shown on a specific page only for mobile devices, for me the perfect solution would be an additional url parameter -> '&product_view=list', before it is redirected to the page.
Thank you!
Share Improve this question asked Apr 20, 2019 at 9:42 SwitchITSwitchIT 12 Answers
Reset to default 0Set a variable
$product_view=isset($_GET['product_view']) ? $_GET['product_view'] : 'grid';
Now, how to keep it like this with pagination URL's.
echo paginate_links(array(
'base' => add_query_arg('product_view', $product_view),
'format' => '',
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => ceil($total / $items_per_page),
'current' => $page,
'add_args' => array(
'category' => 'fruit',
'color' => 'red'
)
));
I hope this will help you to solve your problem.
Thank You,
Maybe you could try using the MobileDetect class (found in Github, I'm not affiliated) to detect if user is using a mobile device, and then add the url parameter with add_query_arg
on template_redirect
action. Something along these lines.
require_once 'Mobile_Detect.php'; // use correct path
function prefix_add_list_view_param_on_mobile() {
$detect = new Mobile_Detect;
$is_product_view = true; // add logic
// Any mobile device (phones or tablets).
if ( $is_product_view && $detect->isMobile() && empty( $_GET['product_view'] ) ) {
wp_safe_redirect( esc_url( add_query_arg( 'product_view', 'list' ) ) ); // omitting url param results in the current URL being used (the value of $_SERVER['REQUEST_URI'])
exit;
}
}
add_action( 'template_redirect', 'prefix_add_list_view_param_on_mobile' );
The code exapmle is untested and might require some tweaking.
本文标签: urlsAdd addtional page parameter before loading the page
版权声明:本文标题:urls - Add addtional page parameter before loading the page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745570803a2664035.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论