【问题标题】:How to use WooCommerce is_shop conditional tag excluding searchs results如何使用 WooCommerce is_shop 条件标签排除搜索结果
【发布时间】:2020-10-08 09:26:02
【问题描述】:

我有一个使用条件标签 is_shop 的函数。

该功能旨在仅在商店页面上显示小部件。 但是,它也会在执行搜索时返回小部件。

有没有办法只在商店主页上退货。

我的代码是:

function cs_beforeproducts_sidebar() {
    if( is_shop() ){
        get_sidebar( 'aboveproducts' );
    } else {
}
}

我也尝试过使用 is_page,但没有任何乐趣。

【问题讨论】:

    标签: php wordpress woocommerce conditional-statements


    【解决方案1】:

    您可以使用 WordPress is_search() 作为条件标签,例如:

    function cs_beforeproducts_sidebar() {
        // Only shop and not a search
        if( is_shop() && ! is_search() ){
            get_sidebar( 'aboveproducts' );
        } else {
            // something else
        }
    }
    

    或者作为产品搜索在URL中添加's'查询变量,可以尝试使用:

    function cs_beforeproducts_sidebar() {
        // Only shop and not search
        if( is_shop() && ! isset($_GET['s']) ){
            get_sidebar( 'aboveproducts' );
        } else {
            // something else
        }
    }
    

    两者都有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      • 1970-01-01
      • 1970-01-01
      • 2011-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多