1.サイト内検索の作り方
参考:
Google カスタム検索(サイト内検索)の設置方法や使い方
Google カスタム検索(サイト内検索)の設置方法や使い方等に関する参考資料・解説。Google 検索エンジンの設定, 検索エンジンの編集, Google カスタム検索のコードの取得, フォームを使用した検索ボックスの作成, Google...
fcintions.php
は
次のようにする
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php function SearchFilter($query) { if ($query->is_search) { $query->set('post_type', array('post','page')); // $query->set('orderby', array('menu_order' => 'ASC' )); // $query->set('orderby', 'menu_order'); // $query->set('order', 'ASC'); // $query->set('post_status', 'publish' ); // $query->set('posts_per_page', 10); return; } return $query; } add_filter('pre_get_posts','SearchFilter'); ?> |
serachform.php
は次のようにする
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<form method="get" action="/%3C?php%20echo%20home_url(%27/%27);%20?%3E" > <input name="s" type="text" value="<?= get_search_query() ?>"> <input type="submit"> </form> <!-- <form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>"> <div> <label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label> <input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" /> <input type="submit" id="searchsubmit" value="<?php echo esc_attr_x( 'Search', 'submit button' ); ?>" /> </div> </form> --> <!----------------------------------------------------------------> |
search.php
は次のようにする。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php $cnt=1; echo '全 '.$wp_query->found_posts.' 件'; foreach($posts as $article) { echo '<p>'; echo '<br>'; echo $cnt.'. '; $cnt++; echo '<a href="/'.get_permalink($article-%3EID).'">'; echo $article->post_title; echo '</a>'; echo '<br>'; echo mb_strimwidth(strip_tags(do_shortcode($article->post_content)), 0, 200, "…",'utf-8'); } ?> |
トップページに次のように入れる
|
1 |
<?php get_search_form(); ?> |
これで出来る
2.googleカスタム検索
Error 404 (Not Found)!!1
にログインする
「新しいい検索エンジン」をクリック
URLを入れる
コードを取得
bing custom search
カスタムポータルにアクセス
Bing Custom Search
ログイン後
Bing Custom Search
にリダイレクト
NEW INSTANCE をクリック Create a new custom search instance
いんすたんすめいを入れる
左右2分割の画面になるので左にurlに対象を入れる
publishで確定
hosted ui タブを開く
snippetのjavascriptをコピー
azureのプロダクションキーを入れる
