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
|
# Highlight query in search results
|
||||||
|
|
||||||
function highlight_results($text) {
|
function limit_text($text, $limit) {
|
||||||
if (is_search() && !is_admin()) {
|
if (str_word_count($text, 0) > $limit) {
|
||||||
$sr = get_query_var('s');
|
$words = str_word_count($text, 2);
|
||||||
$keys = explode(' ', $sr);
|
$pos = array_keys($words);
|
||||||
$keys = array_filter($keys);
|
$text = substr($text, 0, $pos[$limit]);
|
||||||
$text = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="tx-indexedsearch-redMarkup">\0</strong>', $text);
|
|
||||||
}
|
}
|
||||||
return $text;
|
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>';
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,8 @@ get_header();
|
||||||
</span>
|
</span>
|
||||||
</h3>
|
</h3>
|
||||||
<p class="tx-indexedsearch-description">
|
<p class="tx-indexedsearch-description">
|
||||||
<?php the_excerpt(); ?>
|
<!-- <?php the_excerpt(); ?> -->
|
||||||
|
<?php search_excerpt_highlight(); ?>
|
||||||
</p>
|
</p>
|
||||||
<a href="#" class="link-more"><span>Weiterlesen</span></a>
|
<a href="#" class="link-more"><span>Weiterlesen</span></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue