[WordPress] 外掛分享: Highlight Search Terms

首頁外掛目錄 › Highlight Search Terms
WordPress 外掛 Highlight Search Terms 的封面圖片
7,000+
安裝啟用
★★★★★
5/5 分(40 則評價)
10 天前
最後更新
100%
問題解決
WordPress 3.7+ PHP 5.6+ v1.8.3 上架:2009-04-13

內容簡介

這款WordPress外掛能夠在搜索結果頁面上和每個與搜索結果相關聯的文章頁面上突出顯示搜索詞。該外掛輕量且沒有任何選項。它起初是與Thaya Kareeson的《如何使用jQuery突出顯示搜索詞 - 主題hack》和Ryan Boren的Search Hilite插件簡單融合而成。現在進化為具有多種優化、HTML5和bbPress支持的插件。自從1.6版本以來,它不再依賴jQuery庫。

特點:

點擊通過高亮: 不僅在WP搜索結果頁面上進行高亮,也可以從任何找到的頁面中更深入地進行一次點擊。
字符和大小寫不敏感(寬大)突顯顯示
BuddyPress / bbPress兼容:在論壇搜索中進行突顯顯示
快取(WP Super Cache)兼容
用雙引號包裹的搜索詞現在被視為單詞

它是做什麼的?

這個低影響力的插件在搜索結果頁面上找到所有搜索詞,並將它們與<mark class="hilite term-N"> ... </mark>標籤一起突出顯示在每篇文章內部。
請注意,N是從0開始的數字,表示搜索短語中使用的第一個詞,每增加1個詞就會增加1。搜索短語中用引號括起來的任何部分都被視為單個詞。

它不能做什麼嗎?

沒有為突出顯示設置CSS樣式規則。您可以自由地使用任何您喜歡的樣式,但是要使在不支持HTML5的瀏覽器中顯示突顯顯示,如Internet Explorer 8或更老的版本,您絕對需要定義至少一個規則。
現代HTML5瀏覽器將使用它們自己的突顯顯示風格,通常是黃色標記劃線背景。

我需要做什麼?

在大多數情況下,它應該可以正常工作。但是,您可以采取兩件事情來確保向後瀏覽器和主題兼容:

定義CSS規則:沒有配置選項且沒有預定義的高亮樣式。您完全可以在主題的主樣式表(style.css)或WordPress主題自定義選項卡中定義任何CSS樣式規則。
您可以在FAQ中找到基本的說明和CSS示例。

檢查您的主題:在大多數最新的主題(包括WP的自帶主題)中,帖子和頁面內容顯示在帶有class「hentry」的div中。這意味著在帖子和頁面內容中找到的搜索詞會被突出顯示,但在頁面標題、側邊欄或頁腳中意外顯示的類似詞不會被突出顯示。
如果您目前的主題不使用class「hentry」,則此插件將尋找ID「content」、「main」,最後是「wrapper」,但如果找不到這些ID,則不會在您的主題上正常工作。請參閱FAQ中的最後一部分以了解使其運作的方法。

可用的鉤子和過濾器

hlst_query_vars - 插件將識別為搜索查詢的WordPress查詢變量數組。必須返回一個數組。默認值:['search_terms','bbp_search'](WordPress和bbPress搜索)

hlst_input_get_args - 插件將識別為搜索查詢的GET變量數組。必須返回一個數組。默認值:['hilite'](用於單擊通過高亮)

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.8.3) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Highlight Search Terms」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

Highlights search terms within WordPress generated search results, both on the search results page and on each linked post page itself.
This plugin is light weight and has no options. It started as very simple fusion between How to Highlight Search Terms with jQuery – theme hack by Thaya Kareeson and Search Hilite by Ryan Boren. It has since evolved with many optimizations, HTML5 and bbPress support.
Since version 1.6 it no longer depends on the jQuery library.
Features

Click through highlights: Highlights not only on WP search results page but also one click deeper inside any of the found pages
Character and case insensitive (lenient) highlighting
BuddyPress / bbPress compatibility: highlighting within forum searches
Caching (WP Super Cache) compatibility
Search terms wrapped in double quotes now considered as single term

What does it do?
This low impact plugin finds all search terms on a search results page inside each post and highlights them with a ... tag.
Note that N is a number starting with 0 for the first term used in the search phrase increasing 1 for each additional term used. Any part of a search phrase wrapped in quotes is considered as a single term.
What does it NOT do?
There are no CSS style rules set for highlighting. You are free to use any styling you wish but to make the highlights visible in browsers that do not support HTML5 like Internet Explorer 8 or older you absolutely need to define at least one rule.
Modern HTML5 browsers will use their own highlighting style by default, which usually is a yellow marker style background.
So what do I need to do?
In most cases, it should just work. But you can do two things to ensure backward browser and theme compatibility:

Define CSS rules: There are no configuration options and there is no predefined highlight styling. You are completely free to define any CSS styling rules in your themes main stylesheet (style.css) or the Custom CSS tab if the WordPress theme customizer.
You can find basic instructions and CSS examples in the FAQ’s.

Check your theme: In most up to date themes (including WP’s own default theme) post and page content is shown inside a div with class hentry. This means search terms found in post and page content will be highlighted but not similar terms that accidentally show in the page header, sidebar or footer.
If your current theme does not use the hentry class (yet), this plugin will look for IDs content, main and finally wrapper but if none of those are found, it will not work for you out of the box. See the last of the FAQ’s for ways to make it work.

Available hooks and filters

hlst_query_vars – The array of WordPress query variables that the plugin will identify as a search query. Must return an array. Default: ['search_terms','bbp_search'] (WordPress abd bbPress search)

hlst_input_get_args – An array of GET variables that the plugin will identify as a search query. Must return an array. Default: ['hilite'] (for click-through highlighting)

hlst_selectors – The array of possible HTML DOM element identifiers that the script will try. The first viable identifier it finds elements of will be scanned for search terms to mark, the rest is ignored. So the order is important here! Start with the element closest to, but still containing all the post/page title, excerpt or content.

hlst_events – The array of DOM event listeners that the inline script will watch for. Default: ['DOMContentLoaded','post-load'] (on Document Ready and for Jetpack Infinite Scroll and others).

hlst_inline_script – The inline script that will be added to the plugin script file. Can be used to add to or alter the inline script. Must return a string.

Known issues & development

If your theme does not wrap the main content section of your pages in a div with class “hentry” or HTML5 article tags, this plugin might not work well for you out of the box. However, you can make it work. See the last of the FAQ’s for an explanation.

Josh pointed out a conflict with the ShareThis buttons plugin. Since then, that plugin has been completely rewriten so please let me know if the problem still exists. Thanks!

Please file bug reports and code contributions as pull requests on GitHub.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon