wordpress如知更鸟主题增添Yandex自定义站内搜索

已收录   阅读次数: 1,528
2019-11-2422:15:29 发表评论
摘要

众所周知,wordpress站内搜索功能比较薄弱,知更鸟主题也只能增加百度搜索,其他搜索引擎就无能为力了,于是伯衡君想了想,是否也能让其他搜索引擎也添加到站内搜索呢,先前增加了谷歌和必应,再增加一个Yandex,分享给大家,于是就有了今天这篇文章……

分享至:
wordpress如知更鸟主题增添Yandex自定义站内搜索

开篇寄语

众所周知,wordpress站内搜索功能比较薄弱,知更鸟主题也只能增加百度搜索,其他搜索引擎就无能为力了,于是伯衡君想了想,是否也能让其他搜索引擎也添加到站内搜索呢,先前增加了谷歌和必应,再增加一个Yandex,分享给大家,于是就有了今天这篇文章。

效果展示

以本站为例,可以发现本站的搜索增加了七个,达到了八个搜索引擎,如下图所示。

wordpress如知更鸟主题增添Yandex自定义站内搜索

顺序按照如下进行:

  1. 转到https://site.yandex.ru/searches
  2. 获取要添加的代码。
  3. 之后去外观——主题编辑器里修改
  • 咱们先去浏览器键入https://site.yandex.ru/searches,回车键进入yandex自定义搜索引擎设置页面,发现需要登陆才能使用,所以大家可以注册一个yandex账号,方便以后使用,注册成功后再打开上方的网址就可以正式进入设置页面了,如下图所示。
wordpress如知更鸟主题增添Yandex自定义站内搜索
  • 点击新增搜寻,加“*”是必填项目,尤其是搜索区域,请填写自己网站的网址。其他任选,可以参考站长设置的选项,自行填写,如下图所示。
wordpress如知更鸟主题增添Yandex自定义站内搜索
  • 点击下一步,开始设置搜索表单样式,这个自行设置,可以参考站长的设置,如下图所示。
wordpress如知更鸟主题增添Yandex自定义站内搜索
  • 点击下一步,选择在yandex内显示结果。
  • 再点击下一步,开始测试结果,就是在给的搜索框里搜索一下,看能否搜出站内的内容,如果设置没有问题,点击下一步。
  • 这个时候就可以获取代码了,比如站长的代码就是这样的,如下图所示:
<div class="ya-site-form ya-site-form_inited_no" data-bem="{"action":"https://yandex.com/search/site/","arrow":false,"bg":"#ffcc00","fontsize":12,"fg":"#000000","language":"en","logo":"rb","publicname":"Search luckydesigner.space","suggest":true,"target":"_self","tld":"com","type":2,"usebigdictionary":true,"searchid":2368367,"input_fg":"#000000","input_bg":"#ffffff","input_fontStyle":"normal","input_fontWeight":"normal","input_placeholder":null,"input_placeholderColor":"#000000","input_borderColor":"#7f9db9"}"><form action="https://yandex.com/search/site/" method="get" target="_self" accept-charset="utf-8"><input type="hidden" name="searchid" value="2368367"/><input type="hidden" name="l10n" value="en"/><input type="hidden" name="reqenc" value=""/><input type="search" name="text" value=""/><input type="submit" value="Search"/></form></div><style type="text/css">.ya-page_js_yes .ya-site-form_inited_no { display: none; }</style><script type="text/javascript">(function(w,d,c){var s=d.createElement('script'),h=d.getElementsByTagName('script')[0],e=d.documentElement;if((' '+e.className+' ').indexOf(' ya-page_js_yes ')===-1){e.className+=' ya-page_js_yes';}s.type='text/javascript';s.async=true;s.charset='utf-8';s.src=(d.location.protocol==='https:'?'https:':'http:')+'//site.yandex.net/v2.0/js/all.js';h.parentNode.insertBefore(s,h);(w[c]||(w[c]=[])).push(function(){Ya.Site.Form.init()})})(window,document,'yandex_site_callbacks');</script>
  • 是不是很乱啊,其实并没有什么,不用怕,咱们只需要用到一点点里面的东西,一个是https://yandex.com/search/site/,一个是2368367(每个人的都不同),其他毛用没有,设置完成了,我们可以前往后台了。

我们前往后台外观——主题编辑器——searchform.php这个文件,我们要修改它。知更鸟主题默认是这个样子,其他主题是另外的模样,这个对咱们的修改没有影响。

<div class="searchbar">
	<form method="get" id="searchform" action="<?php echo esc_url( home_url() ); ?>/">
		<span class="search-input">
			<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" placeholder="<?php _e( '请输入搜索内容搜索', 'begin' ); ?>" required />
			<button type="submit" id="searchsubmit"><p>本站</p></button>
		</span>
		<?php if (zm_get_option('search_cat')) { ?>
		<span class="search-cat">
			<?php $args = array(
				'show_option_all' => '全部分类',
				'hide_empty'      => 0,
				'name'            => 'cat',
				'show_count'      => 0,
				'taxonomy'        => 'category',
				'hierarchical'    => 1,
				'depth'           => -1,
				'exclude'         => zm_get_option('not_search_cat'),
			); ?>
			<?php wp_dropdown_categories( $args ); ?>
		</span>
		<?php } ?>
	</form>
</div>

我们要对它进行魔改,在</form>这个下面,复制粘贴如下面所列的代码,仅供参考,可以根据站长写的进行魔改:

<br>
	<form method="get" id="searchform" action="https://yandex.ru/search/site/">
		<span class="search-input">
		<input type="text" value="<?php the_search_query(); ?>" name="text" id="s" placeholder="<?php _e( 'Yandex一下,增长见识', 'begin' ); ?>" required />
		<input type="hidden" name="searchid" value="2368367">
		<input type="hidden" name="lr" value="21090">
			<button type="submit" id="searchsubmit"><i class="be be-yandex-international"></i></button>
		</span>
	</form>

在name=“searchid”这个标签内,将value值2368367替换为自己网站的值就可以了,是不是很简单?

  • 我的微信
  • 微信扫一扫加好友
  • weinxin
  • 我的微信公众号
  • 扫描关注公众号
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: