返回介绍

wp_trim_excerpt()

发布于 2017-09-11 13:00:52 字数 2955 浏览 1129 评论 0 收藏 0

wp_trim_excerpt( string $text = '' )

Generates an excerpt from the content, if needed.


description

The excerpt word amount will be 55 words and if the amount is greater than that, then the string ‘ […]’ will be appended to the excerpt. If the string is less than 55 words, then the content will be returned as is.

The 55 word limit can be modified by plugins/themes using the ‘excerpt_length’ filter The ‘ […]’ string can be modified by plugins/themes using the ‘excerpt_more’ filter


参数

$text

(string) (Optional) The excerpt. If set to empty, an excerpt is generated.

Default value: ''


返回值

(string) The excerpt.


源代码

File: wp-includes/formatting.php

function wp_trim_excerpt( $text = '' ) {
	$raw_excerpt = $text;
	if ( '' == $text ) {
		$text = get_the_content('');

		$text = strip_shortcodes( $text );

		/** This filter is documented in wp-includes/post-template.php */
		$text = apply_filters( 'the_content', $text );
		$text = str_replace(']]>', ']]>', $text);

		/**
		 * Filters the number of words in an excerpt.
		 *
		 * @since 2.7.0
		 *
		 * @param int $number The number of words. Default 55.
		 */
		$excerpt_length = apply_filters( 'excerpt_length', 55 );
		/**
		 * Filters the string in the "more" link displayed after a trimmed excerpt.
		 *
		 * @since 2.9.0
		 *
		 * @param string $more_string The string shown within the more link.
		 */
		$excerpt_more = apply_filters( 'excerpt_more', ' ' . '[…]' );
		$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
	}
	/**
	 * Filters the trimmed excerpt string.
	 *
	 * @since 2.8.0
	 *
	 * @param string $text        The trimmed text.
	 * @param string $raw_excerpt The text prior to trimming.
	 */
	return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt );
}

更新日志

Versiondescription
1.5.0Introduced.

相关函数

Uses

  • wp-includes/formatting.php: wp_trim_words()
  • wp-includes/formatting.php: excerpt_length
  • wp-includes/formatting.php: excerpt_more
  • wp-includes/formatting.php: wp_trim_excerpt
  • wp-includes/shortcodes.php: strip_shortcodes()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post-template.php: get_the_content()
  • wp-includes/post-template.php: the_content
  • Show 3 more uses Hide more uses

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文