get_search_form

Sponsored Link

検索フォームを表示するには、searchform.phpテーマファイルを使用します。

Sponsored Link

Display search form using searchform.php theme file.

get_search_formのテンプレートタグ使用方法

<?php get_search_form(); ?>

get_search_formのパラメーター

このタグには、パラメーターが全くありません。

This tag does not accept any parameters.

使用例

テーマでsearchform.phpが使われていなかったとき、Wordpressに検索する組み込みのフォームをレンダリングされます:

When you don’t have searchform.php in your theme, WordPress will render its built-in search form:

<form role="search" method="get" id="searchform" action="http://yourblog.example.com/" >
	<div><label class="screen-reader-text" for="s">Search for:</label>
	<input type="text" value="" name="s" id="s" />
	<input type="submit" id="searchsubmit" value="Search" />
	</div>
</form>

もし、テーマの中にsearchform.phpがあったら、テンプレートをレンダリングします。検索フォームがあなたのブログのホームページにGETをしなければならないことを心にとめておいてください。入力テキストフィールドはsと呼ばれなければなりません、そして、あなたは上の例でのようなラベルを常にインクルードしなければなりません。searchform.phpをカスタムする例:

If you do have searchform.php in your theme, it will render that template instead. Keep in mind that the search form should do a GET to the homepage of your blog. The input text field should be named s and you should always include a label like in the example above. Example of a custom searchform.php:

<form action="/" method="get" accept-charset="utf-8">
<fieldset>
    <label for="search">Search in <?php bloginfo('name'); ?></label>
    <input type="text" name="s" id="search" value="<?php the_search_query(); ?>" />
    <input type="image" alt="Search" src="<?php bloginfo('template_url'); ?>/images/search.png" />
  </fieldset>
</form>

最後のオプションは、カスタム機能(おそらくあなたのfunctions.phpファイルで)を書いて、その機能をget_search_form呼び出しにフックすることです。

A last option is to write a custom function (presumably in your functions.php file) and hook that function to the get_search_form call.

function my_search_form($form) {
$form = '<form method="get" id="searchform" action="' . get_option('home') . '/" >
<div><label class="hidden" for="s">' . __('Search for:') . '</label>
<input type="text" value="' . attribute_escape(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="'.attribute_escape(__('Search')).'" />
</div>
</form>';
return $form;
}
<?php add_filter('get_search_form', 'my_search_form'); ?>

変更ログ

Since: 2.7.0

ソースファイル

get_search_form() is located in wp-includes/general-template.php.

関連テンプレートタグ

get_header, get_footer, get_sidebar, get_template_part, get_search_form, comments_template,

Function Reference/get search form

Sponsored Link