簡體   English   中英

如何僅將搜索表單添加到商店頁面和類別頁面?

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

我正在使用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>
<?php    
if( is_shop() || is_product_category() || is_checkout() ){
   get_search_form();
}
?>

有關woocommerce 條件標簽的更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM