Typecho 主题添加开启和关闭搜索框
admin
撰写于 2023年 05月 10 日

在usr/themes/default/functions.php内加入以下语句

$diySettings = new Typecho_Widget_Helper_Form_Element_Checkbox('diySettings', 
    array('ShowSearch' => _t('显示搜索栏')),
    array('ShowSearch'), 
    _t('自定义设置'));
$form->addInput($diySettings->multiMode());

在usr/themes/default/header.php找到搜索框代码,修改为以下语句

<?php if (!empty($this->options->diySettings) && in_array('ShowSearch', $this->options->diySettings)): ?>
<div class="site-search col-3 kit-hidden-tb">
    <form id="search" method="post" action="<?php $this->options->siteUrl(); ?>" role="search">
        <label for="s" class="sr-only"><?php _e('搜索关键字'); ?></label>
        <input type="text" id="s" name="s" class="text" placeholder="<?php _e('输入关键字搜索'); ?>" />
        <button type="submit" class="submit"><?php _e('搜索'); ?></button>
    </form>
</div>
<?php endif; ?>
<?php if (!empty($this->options->diySettings) && in_array('ShowSearch', $this->options->diySettings)): ?>
<div class="site-search col-3 kit-hidden-tb">
    <form id="search" method="post" action="<?php $this->options->siteUrl(); ?>" role="search">
        <label for="s" class="sr-only"><?php _e('搜索关键字'); ?></label>
        <input type="text" id="s" name="s" class="text" placeholder="<?php _e('输入关键字搜索'); ?>" />
        <button type="submit" class="submit"><?php _e('搜索'); ?></button>
    </form>
</div>
<?php endif; ?>

然后在后台外观设置里就能看到显示搜索框的选项了

Typecho 主题添加开启和关闭搜索框

在usr/themes/default/functions.php内加入以下语句

$diySettings = new Typecho_Widget_Helper_Form_Element_Checkbox('diySettings', 
    array('ShowSearch' => _t('显示搜索栏')),
    array('ShowSearch'), 
    _t('自定义设置'));
$form->addInput($diySettings->multiMode());

在usr/themes/default/header.php找到搜索框代码,修改为以下语句

<?php if (!empty($this->options->diySettings) && in_array('ShowSearch', $this->options->diySettings)): ?>
<div class="site-search col-3 kit-hidden-tb">
    <form id="search" method="post" action="<?php $this->options->siteUrl(); ?>" role="search">
        <label for="s" class="sr-only"><?php _e('搜索关键字'); ?></label>
        <input type="text" id="s" name="s" class="text" placeholder="<?php _e('输入关键字搜索'); ?>" />
        <button type="submit" class="submit"><?php _e('搜索'); ?></button>
    </form>
</div>
<?php endif; ?>
<?php if (!empty($this->options->diySettings) && in_array('ShowSearch', $this->options->diySettings)): ?>
<div class="site-search col-3 kit-hidden-tb">
    <form id="search" method="post" action="<?php $this->options->siteUrl(); ?>" role="search">
        <label for="s" class="sr-only"><?php _e('搜索关键字'); ?></label>
        <input type="text" id="s" name="s" class="text" placeholder="<?php _e('输入关键字搜索'); ?>" />
        <button type="submit" class="submit"><?php _e('搜索'); ?></button>
    </form>
</div>
<?php endif; ?>

然后在后台外观设置里就能看到显示搜索框的选项了

赞 (0)

猜您想看

评论区(暂无评论)

这里空空如也,快来评论吧~

我要评论