WordPress 中文文档
Function Reference/the content
出自WordPress Chinese 中文文档
wordpress.org.cn
目录 |
Description
Displays the contents of the current post. This tag must be within The_Loop.
If the quicktag ttnowiki!--more--/nowiki/tt 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 ttnowiki!--more--/nowiki/tt quicktag point on non-single/non-permalink post pages. By design, ttthe_content()/tt tag includes a parameter for formatting the ttnowiki!--more--/nowiki/tt content and look, which creates a link to continue reading the full post.
- Note about ttnowiki!--more--/nowiki/tt :
- No whitespaces are allowed before the more in the ttnowiki!--more--/nowiki/tt quicktag. In other words ttnowiki!-- more --/nowiki/tt will not work!
- The ttnowiki!--more--/nowiki/tt quicktag will not operate and is ignored in Templates, such as single.php, where just one post is displayed.
- Read Customizing the Read More for more details.
Usage
%%%?php the_content( $more_link_text, $strip_teaser, $more_file ); ?%%%
How to pass parameters to tags with PHP function-style parameters
Parameters
- tt$more_link_text/tt
- (string) (optional) The link text to display for the more link.
- Default: '(more...)'noinclude
div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9
Notes
This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre 已侦测回归模板: Template:Parameter
The usage of this template is below: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre Let's take a closer look at the parameters..
- name
- The name of the parameter.
- datatype
- The datatype that should be given for this parameter when called.
- string
- integer
- boolean
- mixed
- description
- A short description of the parameter.
- importance
- Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
- required
- optional
- default
- If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.
wordpress.org.cn /div /noinclude
- tt$strip_teaser/tt
- (boolean) (optional) Should the text before the more link be hidden (ttTRUE/tt) or displayed (ttFALSE/tt).
- Default: FALSEnoinclude
div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9
Notes
This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre 已侦测回归模板: Template:Parameter
The usage of this template is below: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre Let's take a closer look at the parameters..
- name
- The name of the parameter.
- datatype
- The datatype that should be given for this parameter when called.
- string
- integer
- boolean
- mixed
- description
- A short description of the parameter.
- importance
- Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
- required
- optional
- default
- If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.
wordpress.org.cn /div /noinclude
- tt$more_file/tt
- (string) (optional) File the more link points to (no longer used).
- Default: The current filenoinclude
div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9
Notes
This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre 已侦测回归模板: Template:Parameter
The usage of this template is below: prenowiki已侦测回归模板: Template:Parameter/nowiki/pre Let's take a closer look at the parameters..
- name
- The name of the parameter.
- datatype
- The datatype that should be given for this parameter when called.
- string
- integer
- boolean
- mixed
- description
- A short description of the parameter.
- importance
- Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
- required
- optional
- default
- If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.
wordpress.org.cn /div /noinclude
Examples
Designating the More Text
Displays the content of the post and uses Read more... for the more link text when the ttnowiki!--more--/nowiki/tt Quicktag is used.
?php the_content('Read more...'); ?
Include Title in More
Similar to the above example, but thanks to the_title() tag and the display parameter, it can show Continue reading ACTUAL POST TITLE when the ttnowiki!--more--/nowiki/tt Quicktag is used.
?php the_content(Continue reading . the_title(#39;#39;, #39;#39;, false)); ?
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 ttnowiki!--more--/nowiki/tt Quicktag, for example) you can override the behavior with global $more.
?php global $more; // Declare global $more (before the loop). $more = 0; // Set (inside the loop) to display content above the more tag. the_content(More...); ?
if you need to display all of the content:
?php global $more; // Declare global $more (before the loop). $more = 1; // Set (inside the loop) to display all content, including text below more. the_content(); ?
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 ttnowiki!--more--/nowiki/tt in the content, but for all other posts it will display a more link.
pre ?php if (is_sticky()) {
global $more; // Declare global $more (before the loop). $more = 1; // Set (inside the loop) to display all content, including text below more. the_content();
} else {
global $more;
$more = 0;
the_content('Read the rest of this entry raquo;');
} ? /pre
Alternative Usage
You may use get_the_content() to return the content value instead of outputting it directly. Example:
?php $content = get_the_content(); ?
Please note! get_the_content will return the unfiltered content. If you want to achieve the same output that the_content() returns, use the following code:
?php
$content = apply_filters('the_content', $content);
$content = str_replace(']]', ']]amp;gt;', $content);
?
Changelog
Since: 0.71
Source File
ttthe_content()/tt is located in onlyincludecodewp-includes/post-template.php/code/onlyinclude
div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9
Template Description
Link to the source code on http://core.trac.wordpress.org/browser/.
Parameters
- filename
- (option) path to codetag/code (version) or codetrunk/code. This option is only used for a new function.br /Default: codetrunk/code -- trunk is the latest bleeding edge development version of WordPress.
Usage
Link to the stable version: pre已侦测回归模板: Template:Trac/pre
Link to trunk: pre已侦测回归模板: Template:Trac/pre
/div
wordpress.org.cn.
Related
body_class, next_image_link, next_post_link, next_posts_link, post_class, post_password_required, posts_nav_link, previous_image_link, previous_post_link, previous_posts_link, single_post_title, sticky_class, the_category, the_category_rss, the_content, the_content_rss, the_excerpt, the_excerpt_rss, the_ID, the_meta, the_shortlink, the_tags, the_title, the_title_attribute, the_title_rss, wp_link_pages
includeonlydiv style=clear:both; background-color:#F7F7F7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;See also index of Function Reference and index of Template Tags./div/includeonlynoinclude
Description
This Template is used by Codex:Template Messages.
Usage
pre 已侦测回归模板: Template:Message /pre
Result
已侦测回归模板: Template:Message
/noinclude

