検索方法を2種類おくーカテゴリ別の検索するサーチフォーム

①サーチフォームの表示形式を変更
searchform.phpを以下の内容に置き換えて
ファイル名をsearchform-category.phpに変更する

<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
<label class="hidden" for="s"><?php _e('Key Word Search'); ?></label>
<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
<p>カテゴリを絞る&nbsp;:&nbsp;<?php wp_dropdown_categories('orderby=name'); ?></p>
<input type="submit" id="searchsubmit" value="検索する" />
</form>
<?php
/**
 * Displays the searchform of the theme.
 *
 * @package The NewsMag
 */
?>
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">

<p>category&nbsp;:&nbsp;<?php wp_dropdown_categories( array('show_option_all'=>全てのカテゴリー,'exclude'=>5,1 ,'orderby'=>count,'order'=>DESC)); ?></p>

<label class="hidden" for="s"><?php _e('keyword'); ?></label><input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="検索する" />
</form>
&nbsp;
&nbsp;

実例:selectedタグを外すと過去の検索要素が残る

②サーチ結果を表示するファイルを作成
search.php内容そのままで
search-category.phpとして作成する

③sidebarなど表示したい場所に以下のコードを入れる

<?php get_template_part('searchform-category'); ?>

Posted in php.

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です