描述:
通过ID判断文章是否设置了摘要
用法:
<?php has_excerpt( $id ); ?>
参数:
$id
(integer) (可选) 文章ID
默认值: 当前文章ID
示例:
<?php
// Get $post if you're inside a function
global $post;
if ( has_excerpt( $post->ID ) ) {
// This post has excerpt
} else {
// This post has no excerpt
}
?>
当你需要隐藏自动显示的摘要,只显示你的文章的摘要。
<?php if ( ! has_excerpt() ) {
echo '';
} else {
the_excerpt();
}
替换文本或代码的自动摘要。
<?php if ( ! has_excerpt() ) {?>
<!-- you text or code -->
<?php } ?>
源文件:
/**
* Whether post has excerpt.
*
* @since 2.3.0
*
* @param int|WP_Post $id Optional. Post ID or post object.
* @return bool
*/
function has_excerpt( $id = 0 ) {
$post = get_post( $id );
return ( !empty( $post->post_excerpt ) );
}