WooCommerce 搜索结果模板 [英] WooCommerce search result template

查看:51
本文介绍了WooCommerce 搜索结果模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 WooCommerce WordPress 网站上工作.我为产品添加了 WooCommerce 搜索功能.但是主店页面和搜索结果页面都有相同的模板archive-product.php.但我想要两个页面的单独设计.我该怎么做?

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?

推荐答案

正如@arun 在评论中所说,复制 archive-product.php 并粘贴到主题内的 woocommerce 文件夹中(如果你没有这个文件夹,创建一个)

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)

打开文件并使用 php if 语句拆分该文件中的内容

Open the file and split the content inside that file using a php if statement

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

这篇关于WooCommerce 搜索结果模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆