<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>網站效能 &#8211; 小豬日常</title>
	<atom:link href="https://piglife.tw/tag/%e7%b6%b2%e7%ab%99%e6%95%88%e8%83%bd/feed/" rel="self" type="application/rss+xml" />
	<link>https://piglife.tw</link>
	<description>Hello World，一個紀錄生活與學習的地方</description>
	<lastBuildDate>Fri, 12 Dec 2025 14:46:16 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://piglife.tw/wp-content/uploads/2017/10/cropped-logo-1-32x32.png</url>
	<title>網站效能 &#8211; 小豬日常</title>
	<link>https://piglife.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>利用 Google 自定義搜尋引擎取代 WordPress 站內搜尋功能實作筆記</title>
		<link>https://piglife.tw/technical-notes/google-cse-replace-wordpress-search/</link>
					<comments>https://piglife.tw/technical-notes/google-cse-replace-wordpress-search/#respond</comments>
		
		<dc:creator><![CDATA[小豬]]></dc:creator>
		<pubDate>Thu, 12 Apr 2018 07:23:53 +0000</pubDate>
				<category><![CDATA[技術筆記]]></category>
		<category><![CDATA[google cse]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[前端整合]]></category>
		<category><![CDATA[搜尋優化]]></category>
		<category><![CDATA[站內搜尋]]></category>
		<category><![CDATA[網站效能]]></category>
		<guid isPermaLink="false">https://piglife.tw/?p=310</guid>

					<description><![CDATA[介紹如何使用 Google 自定義搜尋引擎取代 WordPress 站內搜尋，減輕伺服器負擔並提升搜...]]></description>
										<content:encoded><![CDATA[<h2 class="wp-block-heading">前言</h2>
<p>站內搜尋功能對網站效能影響較大，尤其當資料庫資料量龐大時，搜尋速度會變慢。透過 Google 自定義搜尋引擎（Google CSE）可以將搜尋負擔轉移給 Google，減輕伺服器壓力，適合想優化 WordPress 站內搜尋的工程師與自學者。</p>
<h2 class="wp-block-heading">設定 Google 自定義搜尋引擎</h2>
<ol>
<li>進入 <a href="https://cse.google.com/cse/all" target="_blank" rel="noopener">Google 自定義搜尋引擎設定頁面</a>，點擊【Add】新增搜尋引擎。</li>
<li>在「要搜尋的網站」輸入你的網站網域（例如：*.piglife.tw），可設定搜尋範圍。</li>
<li>選擇網站語言（中文網站選擇繁體中文）。</li>
<li>輸入搜尋引擎名稱以便識別。</li>
<li>按下【建立】完成搜尋引擎建立。</li>
</ol>
<h2 class="wp-block-heading">調整搜尋結果顯示設定</h2>
<ol>
<li>建立後點擊【控制台】進入管理頁面。</li>
<li>選擇左側【外觀和風格】，版面配置選擇【只顯示結果】。</li>
</ol>
<blockquote>
<p>選擇「只顯示結果」是因為搜尋表單會將關鍵字傳到此頁面，Google CSE 會在該頁面顯示搜尋結果。</p>
</blockquote>
<ol start="3">
<li>點擊【儲存並取得程式碼】，複製產生的搜尋結果代碼。</li>
</ol>
<h2 class="wp-block-heading">在網站中嵌入搜尋結果代碼與建立搜尋表單</h2>
<ol>
<li>將複製的 Google CSE 代碼貼到你想顯示搜尋結果的頁面（例如 WordPress 的 search.php）。</li>
<li>建立搜尋表單，並設定 form 的 action 指向剛才貼入 Google CSE 代碼的頁面路徑。</li>
</ol>
<p>範例搜尋表單：</p>
<pre><code class="lang-html language-html html">&lt;form role=&quot;search&quot; method=&quot;get&quot; id=&quot;searchform1&quot; class=&quot;search-form&quot; action=&quot;/search&quot;&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;cx&quot; value=&quot;011351595289433252376:t_cbvf510bu&quot; /&gt;
  &lt;input type=&quot;text&quot; name=&quot;q&quot; size=&quot;31&quot; placeholder=&quot;搜尋...&quot; class=&quot;csetext&quot; /&gt;
  &lt;input type=&quot;submit&quot; name=&quot;sa&quot; value=&quot;搜尋&quot; class=&quot;search_btn&quot; /&gt;
&lt;/form&gt;</code></pre>
<ul>
<li><code>action</code>：設定為顯示搜尋結果的頁面路徑。</li>
<li><code>cx</code>：Google CSE 代碼中的搜尋引擎 ID。</li>
<li><code>q</code>：搜尋關鍵字參數。</li>
</ul>
<h2 class="wp-block-heading">實際應用與注意事項</h2>
<p>完成以上設定後，使用者在搜尋表單輸入關鍵字並送出，會跳轉到指定結果頁面並顯示 Google CSE 搜尋結果。搜尋結果會顯示在你貼入代碼的位置，方便自訂版面。</p>
<p>需注意的是，Google CSE 只能搜尋已被 Google 索引的頁面，未被索引的內容不會出現在搜尋結果中。</p>
<h2 class="wp-block-heading">完整程式碼</h2>
<pre><code class="lang-text language-text text">&lt;form role=&quot;search&quot; method=&quot;get&quot; id=&quot;searchform1&quot; class=&quot;search-form&quot; action=&quot;/search&quot;&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;cx&quot; value=&quot;011351595289433252376:t_cbvf510bu&quot; /&gt;
  &lt;input type=&quot;text&quot; name=&quot;q&quot; size=&quot;31&quot; placeholder=&quot;搜尋...&quot; class=&quot;csetext&quot; /&gt;
  &lt;input type=&quot;submit&quot; name=&quot;sa&quot; value=&quot;搜尋&quot; class=&quot;search_btn&quot; /&gt;
&lt;/form&gt;

&lt;!-- 將以下 Google 自定義搜尋引擎代碼貼入 /search 頁面 --&gt;
&lt;script async src=&quot;https://cse.google.com/cse.js?cx=011351595289433252376:t_cbvf510bu&quot;&gt;&lt;/script&gt;
&lt;div class=&quot;gcse-searchresults-only&quot;&gt;&lt;/div&gt;</code></pre>]]></content:encoded>
					
					<wfw:commentRss>https://piglife.tw/technical-notes/google-cse-replace-wordpress-search/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
