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

时间:2016-04-21 14:58:13

标签: javascript php html wordpress woocommerce

我正在使用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>

1 个答案:

答案 0 :(得分:2)

<?php    
if( is_shop() || is_product_category() || is_checkout() ){
   get_search_form();
}
?>

有关woocommerce conditional tags

的更多信息