wp_trim_words [ WordPress Function ]
wp_trim_words ( $text, $num_words = 55, $more = null )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Benzer Fonksiyonlar: wp_trim_excerpt, wp_title_rss, wp_set_password, wp_write_post, wp_timezone_supported
Trims text to a certain number of words.
This function is localized. For languages that count 'words' by the individual character (such as East Asian languages), the $num_words argument will apply to the number of individual characters.
Source
<?php
function wp_trim_words( $text, $num_words = 55, $more = null ) {
if ( null === $more )
$more = __( '…' );
$original_text = $text;
$text = wp_strip_all_tags( $text );
/* translators: If your word count is based on single characters (East Asian characters),
enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
$text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
preg_match_all( '/./u', $text, $words_array );
$words_array = array_slice( $words_array[0], 0, $num_words + 1 );
$sep = '';
} else {
$words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
$sep = ' ';
}
if ( count( $words_array ) > $num_words ) {
array_pop( $words_array );
$text = implode( $sep, $words_array );
$text = $text . $more;
} else {
$text = implode( $sep, $words_array );
}
return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/wp trim words « WordPress Codex
Description. This function trims text to a certain number of words and returns the trimmed text. Usage. <?php wp_trim_words( $text, $num_words = 55, $more ...
codex.wordpress.org - Use wp_trim_words() to limit words in WordPress
Feb 22, 2012 ... wp_trim_words() is a function to limit things like titles and excerpts in WordPress to a particular number of words. Here's an example.
krogsgard.com - Trim Your Text with wp_trim_words() in WordPress | bavotasan.com
May 14, 2012 ... When I first started putting out Premium themes for WordPress, I create a custom excerpt function that would trim your post content to a certain ...
bavotasan.com - wp_trim_words | A HitchHackers guide through WordPress
Dec 13, 2011 ... function wp_trim_words( $text, $num_words = 55, $more = null ) { if ( null === $ more ) $more = __( '…' ); $original_text = $text; $text ...
hitchhackerguide.com