- 构建一个Bootstrap WordPress主题#11 添加搜
- 构建一个Bootstrap WordPress主题#3 添加侧边
- 构建一个Bootstrap WordPress主题#7 添加内容
- 构建一个Bootstrap WordPress主题#5 添加特色
- 构建一个Bootstrap WordPress主题#4 head
- 构建一个Bootstrap WordPress主题#8 添加一点
- 构建一个Bootstrap WordPress主题#2 构建一个
- 构建一个Bootstrap WordPress主题#9 实现一个
- 构建一个Bootstrap WordPress主题#13 开启评
- 构建一个Bootstrap WordPress主题#12 创建文
打开 header.php 文件,找到文件底部空的 form 标签,我们在标签内添加一些内容:
<form method="get" class="navbar-form navbar-right"
role="search" action="<?php echo esc_url(home_url('/')); ?>">
注意:我们把class中的navbar-left修改成right
在action内,我们使用<?php echo esc_url(home_url('/')); ?>把搜索请求提交到主页URL。
- 添加搜索栏
<label for="navbar-search" class="sr-only">
<?php _e('搜索', 'textdomain'); ?>
</label>
<div class="form-group">
<input type="text" class="form-control" name="s" id="navbar-search">
</div>
- 添加搜索按钮(submit):
<button type="submit" class="btn btn-default">
<?php _e('搜索', 'textdomain'); ?>
</button>
保存代码,刷新前端页面,然后搜索 lorem,然后页面显示如下结果:

你还可以尝试搜索其他一些词语。
网友评论