2016-04-21 74 views
1

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

回答

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

更多woocommerce信息conditional tags

+0

正是我一直在尋找謝謝!但是我在哪裏把它放在標題中?因爲當我在endif之後添加它時;聲明,該網站崩潰。 –

+0

@TAA:我已經更新了代碼。它只需要php標籤封裝。現在就試試。 – zipkundan

+0

還要確保在if語句的結尾php標記之後添加此代碼。即在新行('endif;?>')之後。 – zipkundan

相關問題