wordpress WooCommerce 搜索结果模板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23490317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WooCommerce search result template
提问by Arun
I am working on a WooCommerce WordPress site. I have added WooCommerce search feature for product. But both main shop page and search result page have same template archive-product.php. But I want separate design for both pages. How can I do that?
我在 WooCommerce WordPress 网站上工作。我为产品添加了 WooCommerce 搜索功能。但是主店页面和搜索结果页面都有相同的模板archive-product.php。但我想要两个页面的单独设计。我怎样才能做到这一点?
回答by Hooman Askari
As @arun said in the comments copy the archive-product.php and paste in the to the woocommerce folder inside your theme (if you don't have this folder, create one)
正如@arun 在评论中所说,复制 archive-product.php 并将其粘贴到主题内的 woocommerce 文件夹中(如果您没有此文件夹,请创建一个)
Open the file and split the content inside that file using a php if statement
打开文件并使用 php if 语句拆分该文件中的内容
if ( is_search() ) {
//put your search results markup here (you can copy some code from archive-product.php file and also from content-product.php to create a standard markup
} else {
// here goes the content that is already in that file (archive-product.php)
}
Just make sure this line of code always stays at the top of the file:
只要确保这行代码始终位于文件的顶部:
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
回答by Jon
Based on @Capital Themes answer - you can inverse the function and add code for the non search form categories:
基于@Capital Themes 答案 - 您可以反转函数并为非搜索表单类别添加代码:
<?php if (! is_search() ) {
//Added code for non search form
} else {
// if want something only for search
} ?>