自訂搜尋結果
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
您可以為搜尋結果元素新增其他選項,方法與自訂搜尋框類似。
舉例來說,為了將搜尋引擎從網頁搜尋結果
可以使用 defaultToImageSearch
屬性
首先,您必須在搜尋引擎的控制台中啟用圖片搜尋。在「設定」部分的「基本」分頁中,按一下「圖片搜尋」選項,位於「開啟」位置。接著,請將 defaultToImageSearch
屬性新增至網站的 <div class="gcse-searchresults"></div>
元素中。
<!-- 在這裡插入您自己的程式化搜尋引擎 ID -->
<script async src="https://cse.google.com/cse.js?cx=017643444788069204610:4gvhea_mvga"></script>
<!-- 嘗試將屬性值切換為「true」或「false」-->
<div class="gcse-searchbox"></div>
<div class="gcse-searchresults" data-defaultToImageSearch="true"></div>
現在,當您進行搜尋時,系統預設會顯示圖片搜尋分頁。
還有許多其他選擇可以選擇。如要瞭解其他搜尋結果自訂選項,請參閱「Programmable Search Element Control API」一節。
下一步...
繼續執行後續步驟。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eThe search results element can be customized with additional options, such as switching to image-based results using the \u003ccode\u003edefaultToImageSearch\u003c/code\u003e attribute.\u003c/p\u003e\n"],["\u003cp\u003eTo enable image search, you need to activate it in the Control Panel for your search engine and then add the \u003ccode\u003edefaultToImageSearch\u003c/code\u003e attribute to the search results div element.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003edefaultToImageSearch\u003c/code\u003e attribute, when set to "true", makes the image search tab the default view for search results.\u003c/p\u003e\n"],["\u003cp\u003eFurther customization options for search results can be found in the Programmable Search Element Control API documentation.\u003c/p\u003e\n"]]],[],null,["# Customizing Search Results\n\nIn a similar way to customizing search box, you can add additional options to the search results element.\n\nFor example, in order to change our search engine from webresults-based\nto image-based, we can utilize the `defaultToImageSearch` attribute.\n\nFirst of all, you need to enable Image Search in the [Control Panel](https://programmablesearchengine.google.com) for your search engine. In the **Setup** section, in **Basics** tab, click the **Image search** option into the \"on\" position. After that, add the `defaultToImageSearch` attribute to the `\u003cdiv class=\"gcse-searchresults\"\u003e\u003c/div\u003e` element on your website. \n\\\u003c!-- Insert your own Programmable Search Engine ID here --\\\u003e \\\u003cscript async src=\"https://cse.google.com/cse.js?cx=017643444788069204610:4gvhea_mvga\"\\\u003e\\\u003c/script\\\u003e \\\u003c!-- Try switching the attribute value to \"true\" or \"false\" --\\\u003e \n\n \u003cdiv class=\"gcse-searchbox\"\u003e\u003c/div\u003e\n \u003cdiv class=\"gcse-searchresults\" data-defaultToImageSearch=\"true\"\u003e\u003c/div\u003e\n\nNow, when you search for something, the image search tab is showing as a default.\n\nThere are many more options available. You can read about other search results customization options in [Programmable Search Element Control API](/custom-search/docs/element#supported_attributes) section.\n\nNext...\n-------\n\nContinue to [Next steps](/custom-search/docs/tutorial/nextsteps)."]]