wordpress - 添加工具搜索表单 - navwalker - Wordpress
问题描述
我想在我的导航中添加一个循环图标(字体真棒),如果我 clck ,搜索输入表单显示(切换效果)。
在 function.php 中,我添加了以下代码:
function add_search_form($items, $args) {
if( $args->theme_location == 'header-menu' )
$items .= '<li class="search menu-item menu-item-type-custom dropdown menu-item-object-custom"><a class="search_icon"><i class="fa fa-search"></i></a><div style="display:none;" class="searchform">'. get_search_form(false) .'</div></li>';
return $items;
}
jQuery(document).ready(function ($) {
$(".search_icon").click(function () {
$(".searchform").slideToggle();
});
$(document).keydown(function (e) {
if (e.keyCode == 27) {
//$(modal_or_menu_element).closeElement();
$(".searchform").hide();
}
});
});
.searchform {
display: block;
position: absolute;
right: 0;
top: 100%;
margin-top: 1px;
margin-right: 3rem;
z-index: 9999;
background: #fff;
padding: 20px;
background: #343a40;
margin-top: -1px;
}
.container { position:relative;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<li class="search menu-item menu-item-type-custom dropdown menu-item-object-custom">
<a class="search_icon">
<i class="fa fa-search" aria-hidden="true"></i>
</a>
<div style="display:none;" class="searchform">
<!-- search -->
<form class="search" method="get" action="example.com" role="search">
<input class="search-input" type="search" name="s" placeholder="Que cherchez-vous ?">
<button class="search-submit" type="submit" role="button">Ok !</button>
</form>
<!-- /search -->
</div>
</li>
我使用导航器。在我不使用 navwalker 并且此代码有效之前,但现在,当我单击图标时没有任何操作。
任何想法 ?
谢谢
解决方案
推荐阅读
- python - 使用带有 StartTLS 的 ldaptor Python 代理 - 错误 StartTLS 未实现
- python - 基于列值数据和应用条件的Pyspark过滤
- huawei-mobile-services - 华为HMS初始化无Json文件
- c++ - (C++) 这3种类型转换方法有什么区别?
- android - 如何监控资源?
- javascript - 如何仅在活动幻灯片中自动播放 YouTube 视频
- android-studio - 在android studio中选择文本后插入心情自动激活
- python - 当我使用 keras-retinanet / resnet50 获得 0.000 的 mAP 时该怎么办?
- jmeter - 如何在 Jmeter 中达到一定的 TPS
- c# - 我正在从电子表格中读取数据并将其转储到 SQL 数据库中。一列可以有空值,如何让它传递空值?