【问题标题】:How do I add the search form to the shop page & category pages only?如何仅将搜索表单添加到商店页面和类别页面?
【发布时间】:2016-04-22 17:38:44
【问题描述】:

我正在使用 Wordpress 和 Woocommerce 并且有一个商店页面和几个类别页面用于我销售的产品。我想将搜索表单 () 添加到标题中,但仅添加到这些页面中。我确定这与我需要添加到标题的 if (is_shop()) 命令有关,但我对 php/javascript 不是很擅长,因此我寻求你们这些了不起的人的帮助?!那么,如何让搜索栏只显示在商店页面、类别页面和结帐页面标题上,而不是主页、我的帐户页面等?

HTML(header.php 文件):

<div id="page" class="site">
  <a class="skip-link screen-reader-text" href="#main"><?php esc_html_e( 'Skip to content', 'devo' ); ?></a>

  <header id="masthead" class="site-header" role="banner">
    <div class="site-branding">

        <?php
        if ( is_front_page() && is_home() ) : ?>
            <img src="http://myimagefile">
            <!-- <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1> -->

        <?php else : ?>
            <img src="myimagefile">
            <!-- <p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p> -->
        <?php
        endif;

        $description = get_bloginfo( 'description', 'display' );
        if ( $description || is_customize_preview() ) : ?>
            <p class="site-description"><?php echo $description; /* WPCS: xss ok. */ ?></p>
        <?php
        endif; ?>

    </div>
  </header>

【问题讨论】:

    标签: javascript php html wordpress woocommerce


    【解决方案1】:
    <?php    
    if( is_shop() || is_product_category() || is_checkout() ){
       get_search_form();
    }
    ?>
    

    更多关于woocommerce的信息conditional tags

    【讨论】:

    • 正是我一直在寻找的东西,谢谢!但是我在哪里把它放在标题中?因为当我在 endif 之后添加它时;声明,网站崩溃。
    • @TAA:我已经更新了代码。它只需要 php 标签封装。立即尝试。
    • 还要确保在 if 语句的结束 php 标记之后添加此代码。即在新行 (endif; ?&gt;) 之后。
    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 2018-07-01
    • 2018-09-05
    • 2021-04-23
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多