【问题标题】:How can I add custom search box on page?如何在页面上添加自定义搜索框?
【发布时间】:2016-06-09 08:02:53
【问题描述】:

我正在使用自定义 WordPress 模板,但我不知道如何在特定位置添加搜索框。当然我的模板包含搜索框,但它在一个奇怪的地方,所以我想添加一个自定义的。我不能通过添加小部件来做到这一点。我必须编辑index.php 才能添加搜索框。

当我添加这个时:

<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<div><input type="text" size="18" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" class="btn" />
</div>
</form>

基本上,它正在工作。搜索正常,但搜索框不好看。

那个也可以:

<form method="get" id="search_form" action="<?php bloginfo('home'); ?>"/>
       <input type="text" class="text" name="s" value="SEARCH" >
       <input type="submit" class="submit" value=""  />
</form>

但又一次,它看起来很糟糕。我也必须有自定义 css。

还有一个:

<?php get_search_form(); ?>

效果很好,但同样的问题。就像2000年一样。

我尝试添加自定义 css,但问题是 id 没有在我的网站上搜索任何内容。而是转到http://example.com/?s=WHAT-I-TYPED 它转到http://example.com/

我能用它做什么?

【问题讨论】:

  • theme-> editor ->header.php 把你的自定义代码@audiophonic 或者你可以找到一个插件来做到这一点
  • 但自定义 css 显示正常。问题是,当我在每个 custum 搜索框 id 上单击搜索时,根本不会搜索。

标签: php html css wordpress


【解决方案1】:

解决 UGLYNESS 问题:只需添加插件'simple custom css':https://nl.wordpress.org/plugins/simple-custom-css/。然后写一些 CSS 让它变得漂亮。

要解决搜索问题,请将输入字段中的 name="search" 替换为 name="s"(来源:https://developer.wordpress.org/reference/functions/get_search_form/)。

【讨论】:

  • 我将其添加为自定义 css:http://pastebin.com/8zuapgvr 和 index.php 中的 http://pastebin.com/0VG1ykDx 但当我搜索时它转到 http://example.com/?search=test&amp;Search=Search# 而不是 http://example.com/?s=test。我该怎么办?
  • 附言。您的文字中有错字。您应该将“Type your search hear”替换为“Enter your search keywords here”或“Type here to search”。
  • 哦,非常感谢!快完成了。还有一个小错误。当我尝试从www.example.com 搜索时,一切正常。但是当我尝试从www.example.com/page/2 搜索时,它会转到www.example.com/page/2/?s=test 而不是www.example.com/?s=test。结果它什么也没找到。这是css和html:http://www.cssdesk.com/rSJET
  • 那是另一个问题,与这个无关。请添加另一个问题。
  • 答案中的链接 1 是下载链接,链接 2 是参考/文档链接。请再次检查。
猜你喜欢
  • 2016-12-05
  • 2015-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-12
  • 1970-01-01
  • 2021-03-25
相关资源
最近更新 更多