首页 > 解决方案 > 具有 Polylang + 搜索栏功能的革命滑块

问题描述

我有这个代码:

<form role="search" method="get" id="searchform"
class="revtp-searchform" action="https://yourwebsitehere.com">
  <input type="text" value="" name="s" id="s" placeholder="Make your search here" />
  <input type="submit" id="searchsubmit" value="Find" />
</form>

问题是我想为我的英文版本和我的西班牙版本有一个搜索栏。使用上面的代码,它只查找我默认英文版本的帖子。我使用 Polylang。

有人可以帮忙吗?谢谢。

标签: phpwordpresssearchpolylang

解决方案


默认情况下,wordpress 提供一种功能来显示搜索表单

get_search_form();

如果它在主题中可用,它使用 searchform.php,否则它使用 wordpress 的默认搜索形式。您可以在您的子主题中创建一个名称为 searchform.php 的文件,并在下面输入代码

<form role="search" method="get" id="searchform"
class="revtp-searchform" action="<?php echo esc_url(home_url('/') . 'index.php/' . pll_current_language() . '/'); ?>">
  <input type="text" value="" name="s" id="s" placeholder="Make your search here" />
  <input type="submit" id="searchsubmit" value="Find" />
</form>

//pll_current_language() will get current language of polylang


推荐阅读