【问题标题】:Google’s sitelinks search box for Google Custom Search用于 Google 自定义搜索的 Google 附加链接搜索框
【发布时间】:2014-10-16 12:15:12
【问题描述】:

我完全不知道如何将 Google 的附加链接搜索框与 Google 的自定义搜索结合使用。

有人知道我是如何开始连接 2 的吗?

对于站点链接搜索框谷歌给出以下代码:

<script type="application/ld+json">
{
   "@context": "http://schema.org",
   "@type": "WebSite",
   "url": "https://www.example-petstore.com/",
   "potentialAction": {
     "@type": "SearchAction",
     "target": "https://query.example-petstore.com/search?q={search_term_string}",
     "query-input": "required name=search_term_string"
   }
}
</script>

然后你就有了谷歌的自定义搜索代码:

<script>
  (function() {
    var cx = '006674923042857018221:WMX2084923030';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>

究竟如何连接 2?希望你能指出我正确的方向。

【问题讨论】:

    标签: javascript schema.org google-custom-search google-rich-snippets


    【解决方案1】:

    在 Google 提供的 Javascript 代码中有一个 var cx = 'YOUR_LONG_CX_KEY。使用该 URL 模式填写 potentialAction.target

     "target": "http://www.google.com/cse?cx=YOUR_LONG_CX_KEY&q={search_term_string}",
    

    您可以通过在浏览器中使用您自己的搜索字词字符串点击该网址来确认该网址是否有效。

    但是,我不知道 Google 是否会接受 their docs 的“目标”字段说,“这必须是指向与正在搜索的内容相同域中的地址的 URL 模式。”另一方面,同一页面的顶部显示“您的网站没有搜索引擎?您可以使用 Google 自定义搜索引擎设置一个。”

    【讨论】:

      猜你喜欢
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 2019-07-17
      • 2015-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多