如何限制wordpress搜索結果中的內容長度或字符數限制?限制wordpress搜索結果的內容長度
我想要的東西就像the_excerpt()
所做的一樣。
我在我的頁面中使用了get_template_part('loop', 'search')
。然後我必須在search.php
或loop.php
更改。
有沒有辦法做到這一點?
如何限制wordpress搜索結果中的內容長度或字符數限制?限制wordpress搜索結果的內容長度
我想要的東西就像the_excerpt()
所做的一樣。
我在我的頁面中使用了get_template_part('loop', 'search')
。然後我必須在search.php
或loop.php
更改。
有沒有辦法做到這一點?
很多。想起了substr
。一個更復雜的解決方案可能是創建一個函數(在你的主題的functions.php)shorten($content)
,是以文字縮短和:
請看你的wordpress安裝中的wp-includes/formatting.php中的wp_trim_excerpt()
函數。
我如何才能將此應用於搜索結果? –
只在搜索結果模板中使用它。 –
在codex中解釋使用帶過濾器的the_excerpt()怎麼樣?
function new_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');
來源:http://codex.wordpress.org/Function_Reference/the_excerpt#Control_Excerpt_Length_using_Filters約1小時後
我如何將此應用於僅搜索結果? –
所以一年後,你怎麼解決這個問題? – hakre