首页 文章

WooCommerce搜索结果模板

提问于
浏览
5

我正在开发一个WooCommerce WordPress网站 . 我为产品添加了WooCommerce搜索功能 . 但主店铺页面和搜索结果页面都有相同的模板archive-product.php . 但我想要两个页面分开设计 . 我怎样才能做到这一点?

2 回答

  • 12

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

    打开文件并使用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) 
    }
    

    只需确保这行代码始终位于文件的顶部:

    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
  • 0

    基于@Capital主题答案 - 您可以反转该函数并为非搜索表单类别添加代码:

    <?php   if (! is_search() ) {
    //Added code for non search form
    } else {
    // if want something only for search
    }   ?>
    

相关问题