WordPress获取文章摘要函数:get_the_excerpt

文 / @WordPress主题

WordPress函数get_the_excerpt用于获取文章的摘要,通常用在归档页输出文章列表时同时输出文章的摘要,文章页面也可以将摘要作为导读输出,更有用的是将摘要内容作为Descraption标签的内容。

get_the_excerpt( int $post = null )

函数参数

$post

整数型,默认值:null

提供文章的ID以获取该文章的摘要,在Loop主循环中使用时,不传递任何参数即可获取当前文章的摘要。另外,也可以传递WP_Post对象而不是ID

函数使用示例

<?php
	$my_excerpt = get_the_excerpt();
	if ( '' != $my_excerpt ) {
		//您的代码
	}
	echo $my_excerpt; // 输出摘要
?>

扩展阅读

get_the_excerpt()函数位于:wp-includes/post-template.php

相关函数:

  • the_excerpt()
添加UTHEME为好友
扫码添加UTHEME微信为好友
· 分享WordPress相关技术文章,主题上新与优惠动态早知道。
· 微信端最大WordPress社群,限时免费入群。