WordPress 中文文档
Template Tags/the content
出自WordPress Chinese 中文文档
目录 |
Description
Displays the contents of the current post. This tag must be within The_Loop.
If the quicktag ttlt;!--more--gt;/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 ttlt;!--more--gt;/tt quicktag point on non-single/non-permalink post pages. By design, ttthe_content()/tt tag includes a parameter for formatting the ttlt;!--more--gt;/tt content and look, which creates a link to continue reading the full post.
- Note about ttlt;!--more--gt;/tt :
- No whitespaces are allowed before the more in the ttlt;!--more--gt;/tt quicktag. In other words ttlt;!-- more --gt;/tt will not work!
- The ttlt;!--more--gt;/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'); ?%%%
Alternatively, you may use this to return the content value instead of the normal echo:
%%%?php $content = get_the_content(); ?%%%
Please note! get_the_content will not have the following done to it and you are advised to add them until the core has been updated:
%%%?php $content = apply_filters('the_content', $content); $content = str_replace(']]', ']]gt;', $content); ?%%%
Examples
Designating the More Text
Displays the content of the post and uses Read more... for the more link text when the ttlt;!--more--gt;/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 ttlt;!--more--gt;/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 ttlt;!--more--gt;/tt Quicktag, for example) you can override the behavior with global $more.
?php // Declare global $more, before the loop. global $more; ?
?php // Display content above the more tag $more = 0; the_content(More...); ?
Alternatively, if you need to display all of the content:
?php // Declare global $more, before the loop. global $more; ?
?php // Display all content, including text below more $more = 1; the_content(); ?
note: in my case I had to set $more=0; INSIDE the loop for it to work.
Parameters
- more_link_text
- (string) The link text to display for the more link. Defaults to tt'(more...)'/tt.
- strip_teaser
- (boolean) Should the text before the more link be hidden (ttTRUE/tt) or displayed (ttFALSE/tt). Defaults to ttFALSE/tt.
- more_file
- (string) File the more link points to. Defaults to the current file. (V2.0: Currently the 'more_file' parameter doesn't work).
Related
the_ID, the_title, the_title_attribute, single_post_title, the_title_rss, the_content, the_content_rss, the_excerpt, the_excerpt_rss, previous_post_link, next_post_link, posts_nav_link, the_meta,
div style=background: #f7f7f7; border: 1px solid #000; padding: 10px;
How to pass parameters to tags with PHP function-style parameters

