fix search results length and formatting
This commit is contained in:
parent
dae32307ff
commit
ef9644c8d7
2 changed files with 19 additions and 10 deletions
|
|
@ -431,14 +431,22 @@ add_action( 'widgets_init', 'kit_widgets_init' );
|
|||
|
||||
# Highlight query in search results
|
||||
|
||||
function highlight_results($text) {
|
||||
if (is_search() && !is_admin()) {
|
||||
$sr = get_query_var('s');
|
||||
$keys = explode(' ', $sr);
|
||||
$keys = array_filter($keys);
|
||||
$text = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="tx-indexedsearch-redMarkup">\0</strong>', $text);
|
||||
}
|
||||
return $text;
|
||||
function limit_text($text, $limit) {
|
||||
if (str_word_count($text, 0) > $limit) {
|
||||
$words = str_word_count($text, 2);
|
||||
$pos = array_keys($words);
|
||||
$text = substr($text, 0, $pos[$limit]);
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
add_filter('the_excerpt', 'highlight_results');
|
||||
function search_excerpt_highlight() {
|
||||
|
||||
$excerpt = wp_strip_all_tags( get_the_content() );
|
||||
$excerpt = limit_text( $excerpt, 32);
|
||||
|
||||
$keys = implode('|', explode(' ', get_search_query()));
|
||||
$excerpt = preg_replace('/(' . $keys .')/iu', '<strong class="tx-indexedsearch-redMarkup">\0</strong>', $excerpt);
|
||||
|
||||
echo '<p>... ' . $excerpt . ' ...</p>';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue