返回介绍

the_content()

发布于 2017-09-11 10:33:30 字数 5261 浏览 1017 评论 0 收藏 0

the_content( string $more_link_text = null,  bool $strip_teaser = false )

Display the post content.


description


参数

$more_link_text

(string) (Optional) Content for when there is more text.

Default value: null

$strip_teaser

(bool) (Optional) Strip teaser content before the more text. Default is false.

Default value: false


源代码

File: wp-includes/post-template.php

function the_content( $more_link_text = null, $strip_teaser = false) {
	$content = get_the_content( $more_link_text, $strip_teaser );

	/**
	 * Filters the post content.
	 *
	 * @since 0.71
	 *
	 * @param string $content Content of the current post.
	 */
	$content = apply_filters( 'the_content', $content );
	$content = str_replace( ']]>', ']]>', $content );
	echo $content;
}

更新日志

Versiondescription
0.71Introduced.

More Information

If the quicktag <!--more--> is used in a post to designate the “cut-off” point for the post to be excerpted, the_content() tag will only show the excerpt up to the <!--more--> quicktag point on non-single/non-permalink post pages. By design, the_content() tag includes a parameter for formatting the <!--more--> content and look, which creates a link to “continue reading” the full post.

Notes about <!--more--> :

  • No whitespaces are allowed before the “more” in the <!--more--> quicktag. In other words <!-- more --> will not work!
  • The <!--more--> quicktag will not operate and is ignored in Templates where just one post is displayed, such as single.php.
  • Read Customizing the Read More for more details.

相关函数

Uses

  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post-template.php: get_the_content()
  • wp-includes/post-template.php: the_content

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 4You must log in to vote on the helpfulness of this note Contributed by Codex

    Overriding Archive/Single Page Behavior
    If the_content() isn’t working as you desire (displaying the entire story when you only want the content above the <!--more--> Quicktag, for example) you can override the behavior with global $more.

    
    // Declare global $more (before the loop).
    global $more;
    
    // Set (inside the loop) to display content above the more tag.
    $more = 0;
    
    the_content( 'More ...' );
    ?>
    

    If you need to display all of the content:

    
    // Declare global $more (before the loop).
    global $more;
    
    // Set (inside the loop) to display all content, including text below more.
    $more = 1;
    
    the_content();
    
  2. Include Title in “More”
    Show “Continue reading ACTUAL POST TITLE” when the Quicktag is used.

    
    <?php the_content( 'Continue reading ' . get_the_title() ); ?>
    

    Ignore the “More” on a Sticky Post

    This will ignore the more tag in a sticky post–meaning it will display the full content even if there is a <!--more--> in the content, but for all other posts it will display a more link.

    
    // Declare global $more (before the loop).
    global $more;
    
    if ( is_sticky() ) {
    	// Set (inside the loop) to display all content, including text below more.
    	$more = 1;
    
    	the_content();
    } else {
    	$more = 0;
    
    	the_content( __( 'Read the rest of this entry »', 'textdomain' ) );
    }
    

    Designating the “More” Text
    Displays the content of the post and uses “Read more …” for the more link text when the Quicktag is used.

    
    <?php the_content( 'Read more ...' ); ?>
    

    If the content you want to display does not belong to the post declared globally you can use get_extended() which accepts the content as first parameter.

    get_extended($content)

    Reference:
    https://codex.wordpress.org/Function_Reference/get_extended

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文