get_the_content( string $more_link_text = null, bool $strip_teaser = false, WP_Post|object|int $post = null )
检索文章内容。
Retrieve the post content.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$more_link_text | (string) | 可选 | 当有更多文本时的内容。 |
$strip_teaser | (bool) | 可选 | 在更多的文本之前删除摘要内容。默认值为false。 |
$post | (WP_Post | object | int) | 可选 | WP_Post实例或Post ID/对象。默认值为空。 |
返回(Return)
(string)源码(Source)
/**
* Retrieve the post content.
*
* @since 0.71
*
* @global int $page
* @global int $more
* @global bool $preview
* @global array $pages
* @global int $multipage
*
* @param string $more_link_text Optional. Content for when there is more text.
* @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
* @return string
*/
function get_the_content( $more_link_text = null, $strip_teaser = false ) {
global $page, $more, $preview, $pages, $multipage;
$post = get_post();
if ( null === $more_link_text )
$more_link_text = __( '(more…)' );
$output = '';
$has_teaser = false;
// If post password required and it doesn't match the cookie.
if ( post_password_required( $post ) )
return get_the_password_form( $post );
if ( $page > count( $pages ) ) // if the requested page doesn't exist
$page = count( $pages ); // give them the highest numbered page that DOES exist
$content = $pages[$page - 1];
if ( preg_match( '//', $content, $matches ) ) {
$content = explode( $matches[0], $content, 2 );
if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
$more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
$has_teaser = true;
} else {
$content = array( $content );
}
if ( false !== strpos( $post->post_content, '' ) && ( ! $multipage || $page == 1 ) )
$strip_teaser = true;
$teaser = $content[0];
if ( $more && $strip_teaser && $has_teaser )
$teaser = '';
$output .= $teaser;
if ( count( $content ) > 1 ) {
if ( $more ) {
$output .= '' . $content[1];
} else {
if ( ! empty( $more_link_text ) )
/**
* Filter the Read More link text.
*
* @since 2.8.0
*
* @param string $more_link_element Read More link element.
* @param string $more_link_text Read More text.
*/
$output .= apply_filters( 'the_content_more_link', ' ID}" class="more-link">$more_link_text", $more_link_text );
$output = force_balance_tags( $output );
}
}
if ( $preview ) // Preview fix for JavaScript bug with foreign languages.
$output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
return $output;
}
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
5.2.0 | wp-includes/post-template.php:276 | 4 | 12 |
笔记(Notes)
请注意,get_the_content返回的内容与显示的内容不同。为此,您需要执行以下操作:基本用法
在输出前找出内容是否有内容