简体   繁体   English

如何仅将搜索表单添加到商店页面和类别页面?

[英]How do I add the search form to the shop page & category pages only?

I'm using Wordpress & Woocommerce & have a shop page and a few category pages for the products I'm selling. 我正在使用Wordpress和Woocommerce,并且有一个商店页面和一些我要销售产品的类别页面。 I want to add the search form () to the header but only to these pages. 我想将搜索表单()添加到标题中,但仅添加到这些页面中。 I'm sure it's got something to do with a if (is_shop()) command that I need to add to the header but I'm not really good with php/javascript therefore I enlist the help of you amazing people?! 我确定它与if(is_shop())命令有关,我需要将它添加到标题中,但是我对php / javascript的了解不是很好,因此我请大家帮忙! So, how do I get the search bar to only show up on the shop page, category pages & checkout page headers and NOT the home page, my account page, etc.? 那么,如何使搜索栏仅显示在商店页面,类别页面和结帐页面标题上,而不显示在首页,我的帐户页面等上?

HTML (the header.php file): 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>
<?php    
if( is_shop() || is_product_category() || is_checkout() ){
   get_search_form();
}
?>

More info about woocommerce conditional tags 有关woocommerce 条件标签的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM