wp自定义函数代替get_the_excerpt()

如果在摘要框里填写摘要内容,显示摘要内容。否则不会显示文章截取内容。

//在function.php 里添加函数
function get_custom_excerpt( $post = null ) {
    $post = get_post( $post );
    if ( ! $post ) {
        return '';
    }

    $excerpt = $post->post_excerpt;

    return !empty( $excerpt ) ? $excerpt : '';
}

//前台获取函数
<?php $excerpt = get_custom_excerpt();if (!empty($excerpt)) {?><p class="expert"><?php echo $excerpt; ?></p>
                    <?php }?>