デフォルトのサイト内検索フォーム設置
<?php get_search_form(); ?>
自作の検索フォームを設置する場合
1.searchform.phpを作成
最低限のルール
formのmethod属性はGET
action属性はWPのホームURL
name属性がsのinputとlabelを用意
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo home_url(); ?>"> <div> <label class="screen-reader-text" for="s">検索:</label> <input type="text" value="<?php the_search_query(); ?>" name="s" id="s"> <input type="submit" id="searchsubmit" value="検索"> </div> </form>
カテゴリ・タグの絞り込み
カテゴリの絞り込み
<?php $argument = array( 'show_option_none' => 'カテゴリーを選択', 'orderby' => 'name', 'hide_empty' => 0 ); wp_dropdown_categories($argument);
タグの絞り込み
$tags = get_tags(); if ($tags) { ?> <select name="tag" id="tag"> <option value="" selected="selected">タグを選択</option> <?php foreach ($tags as $tag) { ?> <option value="<?php echo esc_html($tag->slug); ?>"><?php echo esc_html($tag->name); ?></option> <?php } ?> </select> <?php } ?>