html Wordpress默认搜索+现场Google CSE

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Wordpress默认搜索+现场Google CSE相关的知识,希望对你有一定的参考价值。

<!-- Create or edit "searchform.php" in theme folder

Replace what is there with the google cse script - example below 

**Note: You will need to edit the final line outside the script with the custom parameters: resultsUrl & queryParameterName

-->

<script>
  (function() {
    var cx = '007001040030262277022:mmdp7u94c6u';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:searchbox-only resultsUrl="/" queryParameterName="s"></gcse:searchbox-only>


<!-- now find or create search.php in your theme to create a results page, then include the code below -->

<gcse:searchresults-only queryParameterName="s"></gcse:searchresluts-only>

<!-- I also like to use the following php snippet for the page title for a custom header -->

<h1><?php printf( __( 'Search Results for: %s', 'betfirm' ), '<span>' . get_search_query() . '</span>' ); ?></h1>


<!-- Now I can reference <?php get_search_form(); ?> anywhere in my theme and keep the results on the default wordpress search results page-->

以上是关于html Wordpress默认搜索+现场Google CSE的主要内容,如果未能解决你的问题,请参考以下文章

html 自定义goog搜索

如何将 WordPress 从现场迁移到本地?

Wordpress SQL 默认搜索,如何处理 SQL 注入

Wordpress和类似Joomla的搜索输入(删除焦点上的默认值)

wordpress如何搜索作者

php WordPress |获取现场所有菜单,添加到选择字段。