get_the_excerpt()
get_the_excerpt( int|WP_Post $post = null ) 检索文章摘要。Retr…
get_the_excerpt( int|WP_Post $post = null )
检索文章摘要。
Retrieves the post excerpt.
检索文章摘要。
Retrieves the post excerpt.
目录锚点:#参数#返回#源码#笔记
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $post | (int | WP_Post) | 可选 | Post ID或WP_Post对象。默认值为全局$post。 |
返回(Return)
(string)后摘录。
源码(Source)
/**
* Retrieve the post excerpt.
*
* @since 0.71
*
* @param mixed $deprecated Not used.
* @return string
*/
function get_the_excerpt( $deprecated = '' ) {
if ( !empty( $deprecated ) )
_deprecated_argument( __FUNCTION__, '2.3' );
$post = get_post();
if ( empty( $post ) ) {
return '';
}
if ( post_password_required() ) {
return __( 'There is no excerpt because this is a protected post.' );
}
/**
* Filter the retrieved post excerpt.
*
* @since 1.2.0
*
* @param string $post_excerpt The post excerpt.
*/
return apply_filters( 'get_the_excerpt', $post->post_excerpt );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 4.5.0 | wp-includes/post-template.php:404 | 4 | 6 |
笔记(Notes)
如果此函数在循环外部使用,并且post没有自定义的摘录,则此函数将使用wp_trim_excerpt()生成摘录。该函数使用get_the_content(),该函数必须与循环一起使用,如果在循环外部使用get_the_excerpt(),则会导致问题。为了避免这些问题,请在调用get_the_execrpt()之前使用set up_postdata()设置全局$post对象。
对HTML元描述使用摘录
将主页上显示的手动摘录限制为260个字符,但在最后一个字后截断
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!