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

标签 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>

最佳答案

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

有关 woocommerce 的更多信息 conditional tags

关于javascript - 如何仅将搜索表单添加到商店页面和类别页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36773403/

相关文章:

php - 如何避免在 "infinite scrolling"系统中从数据库中获取重复的帖子?

javascript - JQuery 工具提示不允许单击按钮

javascript - map 仅在窗口更改时正确显示

php - 无法使用 simplexml_load_file 进入目录

html - css - 修复了在内容下方显示 0.4px 空白的父 div - 无法修复吗?

php - 查询不显示记录

PHP:使用其中一个数组的值对三个数组进行排序。对于我的 Android/iPhone 应用程序至关重要

javascript - 返回新的 Promise() 在 Node.js 中不起作用

javascript - Webgl 中的球体网格

javascript - ES6 映射和减少频率计数