^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_the_excerpt()用法示例

get_the_excerpt( int|WP_Post $post = null )

Retrieves the post excerpt.


描述


参数

$post

(int|WP_Post)
(Optional)
Post ID or WP_Post object. Default is global $post.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

Default value: null


返回值

(string) Post excerpt.


源代码

File: wp-includes/post-template.php

function get_the_excerpt( $post = null ) {
	if ( is_bool( $post ) ) {
		_deprecated_argument( __FUNCTION__, '2.3.0' );
	}

	$post = get_post( $post );
	if ( empty( $post ) ) {
		return '';
	}

	if ( post_password_required( $post ) ) {
		return __( 'There is no excerpt because this is a protected post.' );
	}

	/**
	 * Filters the retrieved post excerpt.
	 *
	 * @since 1.2.0
	 * @since 4.5.0 Introduced the `$post` parameter.
	 *
	 * @param string $post_excerpt The post excerpt.
	 * @param WP_Post $post Post object.
	 */
	return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
}

更新日志

Version 描述
4.5.0 Introduced the $post parameter.
0.71 Introduced.

相关函数

Uses

  • wp-includes/l10n.php:
    __()
  • wp-includes/functions.php:
    _deprecated_argument()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/post-template.php:
    post_password_required()
  • wp-includes/post-template.php:
    get_the_excerpt
  • wp-includes/post.php:
    get_post()
  • Show 1 more use


Used By

  • wp-includes/embed.php:
    the_excerpt_embed()
  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::column_title()
  • wp-includes/feed.php:
    the_excerpt_rss()
  • wp-includes/post-template.php:
    the_excerpt()

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by hearvox

    Use excerpt for HTML meta 描述

    
    <!-- Use Post excerpt for meta 描述.  -->
    <?php if ( is_single() ) { ?>
    <meta name="描述" content="<?php echo wp_strip_all_tags( get_the_excerpt(), true ); ?>" />
    <?php } ?>
    

    (Setting the second parameter of wp_strip_all_tags to true removes left over line breaks and whitespace chars.)

  2. Use

    has_excerpt()

    to prevent a Notice: Undefined offset: -1 in post-template.php

    $excerpt = '';
    if (has_excerpt()) {
        $excerpt = wp_strip_all_tags(get_the_excerpt());
    }

    Otherwise, you could get an Undefined offset -1 warning, do not try to get_excerpt directly to check whether with isset or NULL, you’ll get an undefined offset -1 back

    Example
    get_the_excerpt() can be used to retrieve and store the value in a variable, without outputting it to the page.

    
    <?php
    $my_excerpt = get_the_excerpt();
    if ( '' != $my_excerpt ) {
    	// Some string manipulation performed
    }
    echo $my_excerpt; // Outputs the processed value to the page
    ?>
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈